Jump to content

Tobi C.

Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

3 Neutral

About Tobi C.

  • Rank
    Newbie

Profile Information

  • Gender
    Male
  • Location
    FFM, Germany

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. It was a timing problem. I tried to set headlines of repeater elements that didn't exist on the first ProcessPageEdit::loadPage. The solution was to set min repeaters back to 0 and create the needed repeaters by api on Pages::added. <?php namespace ProcessWire; class SetDefaultValues extends Process implements Module { public static function getModuleInfo() { return array( 'title' => 'Set Default Values', 'version' => 1, 'summary' => __('Set default values on new pages'), 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookAfter('Pages::added', $this, 'createDefaultRepeaterFields'); } public function createDefaultRepeaterFields(HookEvent $event) { $page = $event->arguments(0); if ($page->template == 'my_template') { if (count($page->my_repeater) < 1) { $defaults = array( 'Headline A', 'Headline B', 'Headline n', ); foreach ($defaults as $default) { $r = $page->my_repeater->getNew(); $r->headline = $default; $r->save(); $page->my_repeater->add($r); } $page->save(); } } } } Thanks for helping with this.
  2. Thanx, @horst, I already tried this and some other hooks but they didn't change anythings. I dont think that the hook is the problem as setting the title works.
  3. The hook works fine and quicktesting it by changing the page title it worked like a charm. Digging deeper into it I ran into another problem: It seems that there is a timing problem with the repeater on page > add new. If I create a new subpage, give it a title and hit save the url switches from "/admin/page/add/?parent_id=1" to "/admin/page/edit/?id=1234&new=1". now I am able to see all fields including the repeater. My module changes the title correctly but has no influence to the repeater fields. if I reload the page or click on edit in the page tree it works like expected but not on the first initial form rendering. Here is my current module code: <?php namespace ProcessWire; class SetDefaultValues extends Process implements Module { public static function getModuleInfo() { return array( 'title' => 'Set Default Values', 'version' => 1, 'summary' => __('Set default values on page add / edit'), 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookAfter('ProcessPageEdit::loadPage', $this, 'setDefaultValues'); } public function setDefaultValues(HookEvent $event) { $page = $event->return; if ($page->template == 'my_template') { $defaults = array( 'Default Headline A', 'Default Headline B', 'Default Headline C', ); $page->title = "Default Title"; // this works if ($page->my_repeater) { foreach ($page->my_repeater as $i => $block) { $block->headline = empty($block->headline) ? $defaults[$i] : $block->headline; // only works on edit, not on add } } } } } Any ideas how to solve this problem?
  4. Hi @flydev thanks for your help. The first thread was exactly what I was searching for. $this->addHookAfter('ProcessPageEdit::loadPage', $this, 'onProcessPageEdit'); That did the job just fine.
  5. Hi, I am a little stuck, while trying to set some default headlines for repeater fields when an user creates a new page of a specific template. I think this has to be done with hooks but I dont know which hook to use for that case. The repeater creates a minimum of 4 instances and each contains of a headline and a textarea. Maybe anyone here can help. Thanks.
  6. Hi, I just tried to install this module in ProcessWire 3.0.44 and everything works fine to the point where i have to log in with google and authenticate. Right after that step comes the following error: Could not fetch the accessToken Is this a problem with the current Version or did I miss something? I hope anyone can help to make this great addon working. Thanks in advance!
×
×
  • Create New...