Jump to content

alexcapes

Members
  • Posts

    120
  • Joined

  • Last visited

Everything posted by alexcapes

  1. Not quite sure why but this is now working and copy across all field content (including images)... // Repeater if(count($page->article_list)) { $translation->of(false); $translation->article_list->removeAll(); $lists = $page->article_list; foreach($lists as $item) { $translation->article_list->import($item); $translation->save("article_list"); } }
  2. Hi, I've created a module to copy across field content from one page to another page, which is working well for all fieldtypes, except for repeater fields. This is my current code for repeater fields: // Repeater if(count($page->article_list)) { $translation->of(false); $translation->article_list->removeAll(); foreach($page->article_list as $item) { $translation->article_list->import($item); } $translation->save(); } It copies across the repeaters and the fields within them fine (there are two fields, a textarea and image field). However only the content of the the textarea field is copied - the image field remains blank. (Just for reference it is a single image field). Can anyone help me out in how I might copy the image (and the description) across please? Thanks!
  3. Thank you horst, this is exactly what I was looking for. For those interested, this is my working module below, which adds in icons based on an select options field. <?php class DynamicIcons extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Dynamic icons for the page tree based on field values', 'version' => 1, 'summary' => 'Module to change the icon on the page tree depending on field values.', 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookAfter('ProcessPageListRender::getPageLabel', $this, 'addPageListLabelItems'); } public function addPageListLabelItems($event) { $page = $event->arguments('page'); $page->of(false); // Check options field for correct value if($page->content_type == '1') { // Add fontawesomeicon $styleItem = "<i class=\"fa fa-file-text-o\"></i>"; // Add to pagetree $event->return = $styleItem . $event->return; } } } (This just shows one options but obviously you could add in additional icons for different field values)
  4. Apologies this was a post in the wrong thread. This is where I posted my solution to creating dynamic icons (based on horst's example) https://processwire.com/talk/topic/10213-dynamic-template-icon-based-on-field-value/
  5. Hi, On a project I'm working on I have a select options field that you can select what type of content you're posting. It has the following options: 1=Article 2=Q and A 3=Visual snippet 4=Gallery 5=List The assigned template has an icon (file-text-o), which is great for articles but maybe not so for galleries. Is it at all feasible/possible to change the assigned icon based on a field value within a page? Or even append a page title in the tree with an icon based on a field value?
  6. Thanks for explanation of what's going on here Ryan. I do think it would be very useful to have the option for allowing rendering of the input without changes having any effect and thus keeping the ability to control the visibilty of fields based on that field.
  7. @LostKobrakai thank you, the Dynamic Roles Module is exactly what I'm looking for. I've used it to override and allow 'page-publish' for translators on the 'tag' template.
  8. Hi, In the site I'm surrently creating I have a role for translators that can go and edit and translate unpublished posts. They are not able to publish these pages (as an editor has to approve the pages first). This works great and I've created a module that the editor can publish these posts from the 'master' English version. However these translators need to go and add their translations to pages which are 'tags'. These 'tag' pages are already live, as they are created by a page fieldtype in the English version, so the translator role is not able to 'edit' them (as that would be equivalent to publishing). Is it possible to have the 'publish' permission per template so I could give publish rights to the translators to the 'tag' template but not the 'article' template? Any help much appreciated. - Alex
  9. No access setting on that field at all. The visibilty is set to 'content_type=4' (where '4' is 'gallery'). I tried explicity setting access to 'edit' for the translator role on the gallery field, however still does not show up for the translator (even though 'Gallery' is selected in the 'content_type' options field)
  10. Hi, I'm utilizing the new field level access controls that arrived with 2.6.2 on a new site. I've found however if I apply access controls to a field to 'view' that has visibilty set to a 'only show if' conditional statement, then the field does not display any content at all. So my example is: A translator role has only 'view' access to a field called 'content_type' (note: both 'Access toggles' are ticked to allow viewing of field and API access) There are different fields viewable based on the value of 'content_type' for example there's a image field accessible only if 'gallery' is selected as content type. Even if 'gallery' is selected by superuser, the translator role cannot see or interact with the image field. Am I missing something here - or is this a bug in the new access controls?
  11. public function init() { $this->addHookBefore('ProcessPageView::pageNotFound', $this, 'overrideError'); } public function overrideError($event){ $page = $event->arguments[0]; if($page instanceof Page && $page->is("template.name^=article_")){ return $page->render(); } } This gives me an error: Fatal error: Exception: Page '...' is not currently viewable. Which I can see why, it's trying to render a page that unpublished, so it correctly spits out the error.
  12. Yeah same here too. This is the redirect code that works... public function init() { $this->addHookBefore('ProcessPageView::pageNotFound', $this, 'overrideError'); } public function overrideError($event){ $page = $event->arguments[0]; if($page instanceof Page && $page->is("template.name^=article_")){ $this->session->redirect($page->related_page_language->url); } } This is workable I reckon but the ideal solution would be to able to render the contents of the English version within the page. Going to keep plugging away to see if I can come up with something that works. .
  13. $this->addHookBefore('ProcessPageView::pageNotFound', $this, 'overrideError'); public function overrideError($event){ if($this->page instanceof Page && $this->page->is("template.name*=article")){ return $this->$page->render(); } } This ^ is what I have so far but doesn't seem to be changing anything and is still throwing a 404 unpublished pages.
  14. Rather than a redirect, ideally I'd be able to render the page using the English content. So for example the template file would have checks in whether it was unpublished and if so, grab title, body etc from $page->related_language_page->title, $page->related_language_page->body etc. Would you mind explaining this a little further? Ideally not wanting to do a plain redirect to the English page but just be able to render the page and maybe just do conditionals in the template file.
  15. Hi, I have a custom built module that auto-generates a number of pages (translations) on creation of a master page (English version) and saves them as subpages of their respective languages. Home - Articles (English) -- Article title - French -- Articles --- Article title (unpublished) - German -- Articles --- Article title (unpublished) etc The pages that are created are unpublished and I'd like if possible to be able to pull content for the English version until a translated version is published. Sometimes no translated version will be available so the English content is seen as a 'fallback' here. Currently to a logged out user trying to view an unpublished translation page will see a 404. Could there be a a way to override this behaviour? I'd only want it to be limited to the translations, so template or parent specific. Extra info... Every translated version has a pagefield storing the master English version, so that info is available for pulling out into a template or module. Each article and it's translations have the same name but is / a country code, such as /fr/ or /de/ etc Any help much appreciated!
  16. Ok my bad, I was putting $this->$page... doh. So it's working! However only the deleting was working, but after some trial and error I found out this... if($page->parent_id == 1023){ ..wasn't returning anything. So I tried this instead... if($page->is("template=article_english")){ ... and it seems to all work! Thank you LostKobrakai for your knowledge and patience.
  17. Still no joy... Notice: Undefined variable: pages in /DuplicateArticles.module on line 102 Fatal error: Call to a member function delete() on a non-object in /DuplicateArticles.module on line 102 ... on emptying trash with 'article_english' pages in.
  18. When I attempt to empty the trash this is the error I get... Error: Call to a member function delete() on a non-object (line 102 of /DuplicateArticles.module) This only comes up when trying to empty the trash containing a page using 'article_english' as the template. Does that shed any light?
  19. <?php class DuplicateArticles extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Duplicate Articles When Created In English To All Translations', 'version' => 1, 'summary' => 'Module to create duplicate of English (master) articles as pages in every translated language.', 'singular' => true, 'autoload' => true, ); } public function init() { $this->pages->addHookAfter('added', $this, 'duplicate'); // This hook occurs right after saving the trash status $this->pages->addHook('trashed', $this, 'trashDuplicates'); // This hook occurs right before final deletion $this->pages->addHook('deleteReady', $this, 'deleteDuplicates'); } public function duplicate($event) { $page = $event->arguments[0]; // Only duplicate pages under /articles/ if ($page->parent_id == 1023) { $translations = new PageArray(); $a = new Page(); $a->template = 'article_french'; $a->parent = wire('pages')->get('/fr/articles/'); $a->name = $page->name; $a->title = "{$page->title} (awaiting translation)"; $a->related_page_language = $page; $a->status = Page::statusUnpublished; $a->save(); $translations->add($a); $b = new Page(); $b->template = 'article_spanish'; $b->parent = wire('pages')->get('/es/articles/'); $b->name = $page->name; $b->title = "{$page->title} (awaiting translation)"; $b->related_page_language = $page; $b->status = Page::statusUnpublished; $b->save(); $translations->add($b); $c = new Page(); $c->template = 'article_german'; $c->parent = wire('pages')->get('/de/articles/'); $c->name = $page->name; $c->title = "{$page->title} (awaiting translation)"; $c->related_page_language = $page; $c->status = Page::statusUnpublished; $c->save(); $translations->add($c); $d = new Page(); $d->template = 'article_russian'; $d->parent = wire('pages')->get('/ru/articles/'); $d->name = $page->name; $d->title = "{$page->title} (awaiting translation)"; $d->related_page_language = $page; $d->status = Page::statusUnpublished; $d->save(); $translations->add($d); $e = new Page(); $e->template = 'article_korean'; $e->parent = wire('pages')->get('/ko/articles/'); $e->name = $page->name; $e->title = "{$page->title} (awaiting translation)"; $e->related_page_language = $page; $e->status = Page::statusUnpublished; $e->save(); $translations->add($e); $page->translated_pages->import($translations); $page->save("translated_pages"); } } public function trashDuplicates($event) { $page = $event->arguments[0]; if($page->parent_id == 1023){ foreach($page->translated_pages as $translation){ $pages->trash($translation); } } } public function deleteDuplicates($event) { $page = $event->arguments[0]; // It may be trashed, where the parent is not 1023 if($page->is("template=article_english")){ foreach($page->translated_pages as $translation){ $pages->delete($translation, true); } } } } This is the working module (with deleting functionality not working). I also noticed it's breaking the emptying of trash. I thought this line could be an issue... if($page->is("template=article_english")){ Should this be the templates for the translations not the english version? Can't quite work out which it should be referencing here.
  20. Ah ha! The pagefield is now being successfully filled with all the translated versions when the English article is created. However the deleting functionality doesn't seem to do anything. I thought could this be to do with the fact that I'm deleting unpublished pages?
  21. Thanks so much for your help, using clone now makes sense (ie. you have to do the first one to then clone it, I was slipping up here). Got it working perfectly. You're right it'll be best to only delete translations if the English version is deleted. Still a little way off on exactly the best way to achieve this... So as I'm understanding it, the steps are: An english article has a hidden pagefield with all its translations in If an english article is deleted, all the translation pages listed in that field are deleted Now I'm guessing that when the duplicates are made, I can also populate the pagefield on the English article with all the duplicate translations in step (1)? I'm not quite sure where to start with this within my current module.
  22. Slightly lost on this one, sorry! How would this change what I have? I think I get the logic here - however wouldn't it be that if there *isn't* an English version then it deletes all others? Translated articles therefore can't exist without a 'master' English original. Just to clarify this is for a page field on the translated articles that connects them back to the original English article. I've used this in the templates to to get shared content such as the main image, rather than having to duplicate this content for each translation. I was tearing my hair out trying to get this to work and then realised I hadn't checked 'allow unpublished pages' in the page field settings. Doh. This works perfectly as you have above now. Thank you!
  23. <?php class DuplicateArticles extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Duplicate Articles When Created In English To All Translations', 'version' => 1, 'summary' => 'Module to create duplicate of English (master) articles as pages in every translated language.', 'singular' => true, 'autoload' => true, ); } public function init() { $this->pages->addHookAfter('added', $this, 'duplicate'); } public function duplicate($event) { $page = $event->arguments[0]; // Only duplicate pages under /articles/ if ($page->parent_id == 1023) { $a = new Page(); $a->template = 'article_french'; $a->parent = wire('pages')->get('/fr/articles/'); $a->name = $page->name; $a->title = "{$page->title} (awaiting translation)"; $a->status = Page::statusUnpublished; $a->save(); $b = new Page(); $b->template = 'article_spanish'; $b->parent = wire('pages')->get('/es/articles/'); $b->name = $page->name; $b->title = "{$page->title} (awaiting translation)"; $b->status = Page::statusUnpublished; $b->save(); $c = new Page(); $c->template = 'article_german'; $c->parent = wire('pages')->get('/de/articles/'); $c->name = $page->name; $c->title = "{$page->title} (awaiting translation)"; $c->status = Page::statusUnpublished; $c->save(); $d = new Page(); $d->template = 'article_russian'; $d->parent = wire('pages')->get('/ru/articles/'); $d->name = $page->name; $d->title = "{$page->title} (awaiting translation)"; $d->status = Page::statusUnpublished; $d->save(); $e = new Page(); $e->template = 'article_korean'; $e->parent = wire('pages')->get('/ko/articles/'); $e->name = $page->name; $e->title = "{$page->title} (awaiting translation)"; $e->status = Page::statusUnpublished; $e->save(); } } } Ok my first module... and it works! Woah. I'm only showing 5x languages above. Eventually there will be 12. Is 12x actions on a page save okay? So now I need to figure out... - More elegant way of creating each new page - there's a lot of duplicated code - A way of deleting the translated pages if the English is deleted - A way of pre-filling a pagefieldtype with the English page - this pagefieldtype is to to explicitly set the related English version to the translated version. I tried adding... $a->id = $page->related_page_language->id; But that doesn't do anything. Anyone know how I might achieve this?
×
×
  • Create New...