Jump to content

[SOLVED] BUG : Repeater fields appears in template settings of any page


abmcr
 Share

Recommended Posts

I have a strange behavior with the last  PW   3.0.76 (debug mode on) ; i have created only 3 templates as you see in the first attachment, but in the settings tab of page i see, as possible template, my various repeater fields...

This is a bug or i have broken some thing?

Thank you in advance and apologize for english language, very poor

 

Schermata 2017-09-27 alle 20.06.10.png

Schermata 2017-09-27 alle 20.05.45.png

Link to comment
Share on other sites

Im still trying to see if I can duplicate your issue on my end, but I do see that an issue was created in June regarding the same thing: 

https://github.com/processwire/processwire-issues/issues/287

However, it does not seem like Ryan could duplicate it either. Ill keep testing, though hopefully someone else will have an actual answer for you.

  • Like 2
Link to comment
Share on other sites

15 minutes ago, louisstephens said:

Im still trying to see if I can duplicate your issue on my end, but I do see that an issue was created in June regarding the same thing: 

https://github.com/processwire/processwire-issues/issues/287

However, it does not seem like Ryan could duplicate it either. Ill keep testing, though hopefully someone else will have an actual answer for you.

Thank you

 

Link to comment
Share on other sites

It is very strange, on my 3.0.61 dev/testing site, I do have the repeaters showing up in the template select.  I created a test_repeater for this, and as You can see, it is displaying at the bottom of the list in my screenshot. I have $config->advanced = false;  (what Ryan was asking in the github issue), and to be honest I am pretty confused as to why this is showing up. Does anyone else have this occurring in a dev setup or a live?

59cc1749a90c8_ScreenShot2017-09-27at5_23_25PM.png.a76cda78b611c2a4c6b47774f0d81a3d.png

Note: test_repeater has 5 items added to it (used on 1 template, but the specials repeat has 4 items , but is being used on multiple pages (I guess where the duplication comes from).

Link to comment
Share on other sites

Repeater templates are set to have no parents

// FieldtypeRepeater.module
/**
 * Populate the settings for a newly created repeater template
 * @param Template $template  */
protected function populateRepeaterTemplateSettings(Template $template) {
    $template->flags = Template::flagSystem;
    $template->noChildren = 1;
    $template->noParents = 1; // prevents users from creating pages with this template, but not us
    $template->noGlobal = 1; 
}

which should be enough to keep them off of ProcessPageEdit (page edit screen, template option at settings tab)

/**
 * Returns an array of templates that are allowed to be used here
 * @return array|Template[] Array of Template objects
 */
protected function getAllowedTemplates() {

    // ...

    foreach($allTemplates as $template) {
        // ...

        } else if($template->noParents) {
            // user can't change to a template that has been specified as no more instances allowed
            // except for superuser... we'll let them do it
            continue;
        } // ...
    }

    return $templates;
}

and ProcessPageAdd (new page screen)

protected function ___getAllowedTemplates($parent = null) {
    // ...
    foreach($allTemplates as $t) {
        // ...
        } else if($t->noParents) {
            continue;
        }

        // ...
        $templates[$t->id] = $t;
    }
    // ...
    return $templates;
}

But seeing how they still show up, I'm guessing somehow $noParents is corrupted to a falsy value. Checking the DB, you shouldn't have noParents entry in templates table for repeater templates. Otherwise I'm not sure how it's possible at all.

image.thumb.png.00f77a3726feaaafa3f2508b5e151eae.png

Link to comment
Share on other sites

Hmm. One thing I missed is that ProcessPageEdit allows super users to pick any template

// ProcessPageEdit.module
protected function getAllowedTemplates() {
    // ... 

    foreach($allTemplates as $template) {
        // ...

        if($isSuperuser) { 
            $templates[$template->id] = $template;
        } else if($template->noParents == -1) {
            // only one of these is allowed to exist
            if($template->getNumPages() > 0) continue;
        } else if($template->noParents) {
            // user can't change to a template that has been specified as no more instances allowed
            // except for superuser... we'll let them do it
            continue;
        // ...
    }
    // ...
    return $templates; 
}

I dont think picking repeater templates should be allowed. if block shouldn't start with checking superuser, but it should come after. This order should stop repeater templates from showing.

if($template->noParents == -1) {
    // only one of these is allowed to exist
    if($template->getNumPages() > 0) continue;

} else if($template->noParents) {
    // user can't change to a template that has been specified as no more instances allowed
    // except for superuser... we'll let them do it
    continue;

} elseif($isSuperuser) {
    $templates[$template->id] = $template;
} 

Can someone confirm changing the order (ProcessPageEdit.module, at line 1973) fixes the issue? 

  • Like 3
Link to comment
Share on other sites

8 hours ago, abdus said:

Hmm. One thing I missed is that ProcessPageEdit allows super users to pick any template


// ProcessPageEdit.module
protected function getAllowedTemplates() {
    // ... 

    foreach($allTemplates as $template) {
        // ...

        if($isSuperuser) { 
            $templates[$template->id] = $template;
        } else if($template->noParents == -1) {
            // only one of these is allowed to exist
            if($template->getNumPages() > 0) continue;
        } else if($template->noParents) {
            // user can't change to a template that has been specified as no more instances allowed
            // except for superuser... we'll let them do it
            continue;
        // ...
    }
    // ...
    return $templates; 
}

I dont think picking repeater templates should be allowed. if block shouldn't start with checking superuser, but it should come after. This order should stop repeater templates from showing.


if($template->noParents == -1) {
    // only one of these is allowed to exist
    if($template->getNumPages() > 0) continue;

} else if($template->noParents) {
    // user can't change to a template that has been specified as no more instances allowed
    // except for superuser... we'll let them do it
    continue;

} elseif($isSuperuser) {
    $templates[$template->id] = $template;
} 

Can someone confirm changing the order (ProcessPageEdit.module, at line 1973) fixes the issue? 

Yes this fixes the issue. Thank you very mutch

Link to comment
Share on other sites

  • abmcr changed the title to [SOLVED] BUG : Repeater fields appears in template settings of any page

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...