gebeer

Page referencefield - custom PHP code not working in repeater

3 posts in this topic

Hello,

on a fresh 3.0.62 install I have a page reference field 'mypages' with these settings for selectable pages:

59520a3a3f892_2017-06-27093239.thumb.png.fc7b4fd4029ecb29161e69587a54b494.png

In my site/ready.php I have this hook:

/**
 * custom page select
 */
wire()->addHookAfter('InputfieldPage::getSelectablePages', function($event) {

  if($event->object->name != 'mypages') return;
 
  $pages = new PageArray();
  $pages->add($this->pages->get(1));
  $ids = $pages->explode('id');
  $event->return = $event->pages->getById($ids);

});

On a normal page, the hook is working and the mypages field has only 'Home' in the select dropdown .

But when I put the mypages field inside a repeater, it is not working.

I have this problem on a project that is in development right now and have spent quite some time to try and find the reason. Then I made a fresh PW install to verify the behavior.
No matter if repeater dynamic loading is on or off, the page reference field always returns the  set of pages defined by the settings in the page reference field. The hook is ignored.

Can anyone please verify this and let me know so I can file a bug report. Also if you have an idea how to fix this, I would be happy.

 

Share this post


Link to post
Share on other sites

@Robin S thank you! I didn't find this in my search. Great that it is being taken care of :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By holmescreek
      I've been trying to figure a way to output the values of several fields within a single repeater using a foreach() without having to reference the name of the fields.
      Typically, for repeaters, I understand you would do foreach($repeater_field as $afield) { echo $afield->fieldname_a; } pretty straight forward.
      Anyways, what I'm doing is using a single repeater as just a container for other fields.
      I've tried using $page->my_repeater->getArray(), then looping through the array, and all sorts of methods, without luck. It seems I must specify the field name for output.
      For instance, my (single) repeater is set up to hold a few different fields:
      my_repeater
      field_a field_b field_c Trying to output it using something like this:
      foreach($page->my_repeater as $afield) {      echo $afield->value;   // I'm not wanting to have the reference the field name e.g. use $afield->field_a }  
      Any suggestions?
       
    • By Sipho
      Is there a module or plugin that is like a repeater but you can choose a template? I want something that let's me:
      choose a template to get fields from, display these fields like a repeater does add new pages without adding a title or name (this might be achievable using other means like ProcessSetupPageName)  delete pages I feel like somebody might have already made a module that does just this, however, I haven't found any. Perhaps there is a way of doing this with a standard repeater that I don't know about.
    • By jothanne
      I have a problem realizing a picture gallery with albums using repeater fields.
      Here is what I have:
      - The repeater field 'repeater_gallery' for all the albums
      - A text field 'album_name' in the repeater for the album name
      - An image field 'album_images' in the repeater for all the album images
      Now I'd like to pick a small selection of images (say 4) of ALL albums randomly and present them with their associated album name.
      How can this be done with the described repeater setup? Or is there a better way to realize such a gallery without repeaters?
      Thanks in advance for a little help.
    • By creativejay
      My brain is probably just tiring out on me right this moment, I'm hoping that by the time I write out my problem I'll see the way through it. If you're reading this, it didn't work.
      Structure in question is:
      Series Page Product pages Page Fields for each product page Some of these fields are repeaters Fields within the repeater I have made an array of page fields so I don't have to keep track of them all as I develop:
      $listings = $page->children; // grab all the published children of the Series page foreach($listings as $l) { // loop through the children foreach($l->fields as $f) { } // loop through each child's page fields where they have a value set } Then I break down how to handle each type of field:
      if($f->type == 'FieldtypeFile') { } elseif($f->type == 'FieldtypeDatetime'||$f->name == 'prod_status_pages'||$f->type == 'FieldtypeImage'){ } elseif($f->type == 'FieldtypePage'){ } These are all largely working as expected (though I do have a couple of offset/isset exceptions to clean up...)
      It's when I get to the repeaters that I run into trouble getting the API calls to work.
      Just cycling through the fields as above, the output for a FieldtypeRepeater is the ID of the repeater in that field's array. Everything I read suggests I should treat a repeater the same as I would treat a page, which leads me to the following code.
      elseif($f->type == 'FieldtypeRepeater'){ // Repeaters need special treatment otherwise output is just ID $th .= "<th><b>{$f->label}</b></th>\n"; $trows = ""; // creating an empty variable to build my foreach into foreach($f->fields as $rf){ // looping, I hope, through the fields of the given Repeater ID $trows .= "{$rf->label}: {$f->get($rf)->title} ({$rf->type})<br />\n"; // add an entry to the variable } $rows .= "<td style='padding: 8px 16px; vertical-align: middle;'>".$trows."<br />\n ({$f->type})</td>\n"; // back out to rendering the Repeater field }  
      What I would hope would output in the HTML I've been building is something like:
       
      <td style='...'>Lo temp: -40 (Integer)<br /> Hi temp: 75 (Integer)<br /> Storage Lo: -40 (Integer)<br /> Storage Hi: 85 (Integer)<br /> Functional to: 85 (Integer)<br /> (FieldtypeRepeater)</td> So what I'm trying to do here is loop through the populated fields in the unknown Repeater field, and output them as a simple (so far) text list of the repeater.field and its value (and then its type for my reference).
      I'm afraid typing this out has fixed some syntax but not enough to get this working as I'd hoped.
      Please note not all Repeater fields are integers. Some also have floats, files, or options, and probably a couple others I'm forgetting.
       
      I appreciate your time in taking a look at this!
    • By nasenfloete
      Hey awesome PW-Community,
      I've some strange behaviour in my latest project and I don't know how to get on top of it:
      I added a repeater field to the User-template. In my project I create a new user than assign items to the repeater.  This works perfect, if the new user has the role "superuser" but if I create a new role (even if assign that role all permissions possible), I can't add items to the repeater via the api.
      I even checked the permissions of the repeater and assigned all permissions to the newly created role. There are also no error logs, even though it seems like the creation of a new repeater element fails.
      Thanks in advance for your help!