Jump to content
MichaMichaMicha

Issue when creating pages with RepeaterField

Recommended Posts

I've stumbled upon a weird issue with repeaters.

I've created a repeaterfield with only a title field and assigned it to a template.

When I create the first page everything goes well, but then when I'm creating additional pages I'm getting this error:

ProcessPageAdd: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'for-page-23947-23799' for key 'name_parent_id'

I'm not getting redirected (probably because of the error, but the page does get created with the RepeaterField correctly).

The problem seems to exist in the file FieldtypeRepeater.module in the function 'getRepeaterPageParent'.

I've modified the file to see what actually happens and it looks like the function doesn't find the required page of saves the page correctly.

protected function getRepeaterPageParent(Page $page, Field $field) { 

		$repeaterParent = $this->getRepeaterParent($field);
		

		
		$parent = $repeaterParent->child('name=' . self::repeaterPageNamePrefix . $page->id . ', include=all'); 
		$this->message("L".__LINE__." | selectorresult: ".$parent->id);
		
		if($parent->id) return $parent; 


		$parent = new Page();
		$parent->template = $repeaterParent->template;

		$this->message("L".__LINE__." | template: ".$repeaterParent->template);
		$this->message("L".__LINE__." | parent: ".$repeaterParent->path);
		$parent->parent = $repeaterParent->id; 
		$parent->name = self::repeaterPageNamePrefix . $page->id;
		$parent->title = $page->name;
		$parent->addStatus(Page::statusSystem);

		// exit early if a field is in the process of being deleted
		// so that a repeater page parent doesn't get automatically re-created
		if($this->deletePageField === $field->parent_id){
			return $parent; 
		}

		$parent->save();
		
		$this->message("L".__LINE__." | looking for: ".self::repeaterPageNamePrefix . $page->id);
		$this->message("L".__LINE__." | current for: ".$parent->name);
		$this->message("L".__LINE__." | Created Repeater Page Parent: NAME={$parent->name} a " . $parent->path, Notice::debug); 

		return $parent; 
	}

See the attachment for the output. IMO the second time FieldtypeRepeater: L574 |  should output the previously created page...

Anyone has an idea what's going wrong? I'm on the latest master branch.

post-943-0-89910200-1403594816_thumb.png

Share this post


Link to post
Share on other sites

Finally got a workaround for this.

Simply added 

$this->pages->uncache($repeaterParent); 

after

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module#L556

When debugging is on in config.php you see the message twice:

Session: Created Repeater Page Parent: /admin/repeaters/for-field-140/for-page-24397/

Not the prettiest solution but at least the client can add pages again.

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 neonwired
      I'm hoping someone has seen this before. There doesn't appear to be an issue with the user info.

       

    • By Robin S
      This is a module I made as an experiment a while ago and never got around to releasing publicly. At the time it was prompted by discussions around using Repeater fields for "page builder" purposes, where the depth feature could possibly be used for elements that would be nested inside other elements. I thought it would be useful to enforce some depth rules and translate the depth data into a multi-dimensional array structure.
      I'm not using this module anywhere myself but maybe it's useful to somebody.
      Repeater Depth Helper
      This module does two things relating to Repeater fields that have the "Item depth" option enabled:
      It enforces some depth rules for Repeater fields on save. Those rules are:
      The first item must have a depth of zero. Each item depth must not be more than one greater than previous item depth. It provides a RepeaterPageArray::getDepthStructure helper method that returns a nested depth structure for a Repeater field value.
      Helper method
      The module adds a RepeaterPageArray::getDepthStructure method that returns a multi-dimensional array where the key is the page ID and the value is an array of nested "child" items, or null if there are no nested children.
      Example

      The module doesn't make any assumptions about how you might want to use the depth structure array, but here is a way you might use it to output a nested unordered list.
      // Output a nested unordered list from a depth structure array function outputNestedList($depth_structure, $repeater_items) { $out = "<ul>"; foreach($depth_structure as $page_id => $nested_children) { $out .= "<li>" . $repeater_items->get("id=$page_id")->title; // Go recursive if there are nested children if(is_array($nested_children)) $out .= outputNestedList($nested_children, $repeater_items); $out .= "</li>"; } $out .= "</ul>"; return $out; } $repeater_items = $page->my_repeater; $depth_structure = $repeater_items->getDepthStructure(); echo outputNestedList($depth_structure, $repeater_items);
       
      https://github.com/Toutouwai/RepeaterDepthHelper
      https://modules.processwire.com/modules/repeater-depth-helper/
    • By ICF Church
      Hi 👋
      Anyone else having this problem?
      Requirements:
      - Repeater (matrix & normal) with mutlilanguage fields (text, textarea…) 
      - Backend language set to something other than default (ie. German) 
      Reproduce:
      - Add a new repeater Item (ajax, I found no way to possible to disable it with matrix)

      (Notice how the default language tab is active instead of the backend language…)
      - Write something into the (default language) field
      - Try to save, if field is required, this will not work. If not required, then when reloading, the content will be inside the backend language field, instead of the default language field who was (presumably) active
      Analysis:
      When  loading  a new repeater element with ajax, the default langue tab is active, but the backend language inputfield is visible (with no visual indication). When writing into the field, it will populate the backend language. When manually clicking on the default language tab (which is already active), the field will switch to the actual default language field (which is [now] empty) (that can now be populated…)
      Also Notice, the labels of the elements to be added are in default language as well instead of the translated label (images instead of Bilder)…
      ProcessWire 3.0.148, Profields 0.0.5…
      Is it my system configuration, or does anyone else have the same issue? This is a screen recording of the problem:
      Issue: https://github.com/processwire/processwire-issues/issues/1179

      Screen Recording 2020-02-25 at 14.18.31.mov
    • By neonwired
      I have a front end form for creating new pages, repeater and repeater matrix field don't seem to save any data. I was considering handling the data manually but can't seem to get anything useful from the post data, are there any methods i can use?
    • By Pip
      Hi, Everyone! 
      I'm currently working on a page reference field and set it for multiple pages (AsmSelect) for the input. Is there a way for me to add an image field (aka Avatar) and the title of page in the radio button? 
      I used the field name enclosed in the { }. Didn't work. It appeared a text instead. 
      Thanks in advance and hope to hear from you soon!
×
×
  • Create New...