apeisa Posted December 9, 2011 Share Posted December 9, 2011 I am creating page-field through API, and I want to set it to allow only certain template and parent. How to achieve this? Link to comment Share on other sites More sharing options...
ryan Posted December 10, 2011 Share Posted December 10, 2011 Here are the fields you can set with a Page field: <?php $f = $fields->get("some_page_field"); // InputfieldPage settings $f->parent_id = 123; // ID of allowed parent page $f->template_id = 4; // ID of allowed template $f->findPagesCode = 'return $page->parent->children();'; // alternate code to use for included pages $f->labelFieldName = 'title'; // name of field to use as label (default is title) $f->inputfield = 'InputfieldSelect'; // class name of inputfield you want to delegate selection to // FieldtypePage settings $f->derefAsPage = FieldtypePage::derefAsPageArray; // Multiple pages (PageArray) $f->derefAsPage = FieldtypePage::derefAsPageOrFalse; // Single page (Page) or boolean false when none selected $f->derefAsPage = FieldtypePage::derefAsPageOrNullPage; // Single page (Page) or empty page (NullPage) when non selected The Inputfield settings only affect what is displayed in the admin (i.e. for locating what pages it should display as selectable). 3 Link to comment Share on other sites More sharing options...
apeisa Posted December 10, 2011 Author Share Posted December 10, 2011 Thanks Ryan! Link to comment Share on other sites More sharing options...
bora Posted August 16, 2015 Share Posted August 16, 2015 Reviving an old topic but which hook should I use for changing this behaviour with a module. When I use this code in admin.php it works perfectly but I could manage to use it with hooks. $field = $fields->get("product_group"); $field->findPagesCode = 'return $page->rootParent->child("name=product-groups")->children();'; Link to comment Share on other sites More sharing options...
bora Posted August 16, 2015 Share Posted August 16, 2015 UPDATE: I saw this post from apeisa after posting this. ProcessPageEdit::buildForm worked like a charm. public function init() { $this->addHookAfter("ProcessPageEdit::buildForm", $this, 'setProductGroup'); } public function setProductGroup(HookEvent $event) { $form = $event->return; $field = $form->get('product_group'); if($field) { $field->findPagesCode = 'return $page->rootParent->child("name=product-groups")->children();'; } $event->return = $form; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now