-
Posts
364 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jploch
-
[SOLVED] Hook not working inside module
jploch replied to jploch's topic in Module/Plugin Development
I already tried that, but no success ? It's strange because the hook works in ready.php or admin.php -
Hi folks, i try to use a hook to change some markup inside admin, this hook works fine inside a ready.php file, but its not working inside my module: <?php namespace ProcessWire; class InputfieldPageTableExtendedGrid extends InputfieldPageTable { public static function getModuleInfo() { return array( 'title' => __('Inputfield for PageTableExtendedGrid', __FILE__), // Module Title 'summary' => __('Adds Inputfield for PageTableExtendedGrid', __FILE__), // Module Summary 'version' => 233, 'requires' => array('FieldtypePageTableExtendedGrid'), 'permanent' => false, ); } public function ready() { $this->addHookAfter('Page::render', function($event) { $value = $event->return; // Return Content $style = "<style type='text/css'>". $this->pages->get((int) wire('input')->get('id'))->style ."</style>"; // Add Style inside bottom head $event->return = str_replace("</head>", "\n\t$style</head>", $value); // Return All Changes }); } } whats wrong here?
-
After some testing it turns out that, if the page hosting the repeater has children it is no longer replacing the runtimeMarkup field.
-
@MarkE Its working now! Thanks for your help! It finally worked with the first code you postet. Before I used the "Updated version here - works with more field types" code example. The first code works perfectly with my page select field and your adjustments. I will send you a copy of my module once its ready, it adds drag and drop, resize support for repeater and repeater matrix fields and uses this code to ajax update page reference blocks inside repeaters and renders them with RuntimeMarkup ? . Maybe I find a way to improve this approach. It would be cool if this could be a feature of the RuntimeMarkup Module someday. I still need to learn more about PHP and PW, I am ok with javascript and frontend stuff..
-
the only error I get is this with tracy: HP Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior
-
ok thanks for clarification and sorry for my slow following here! I inserted my field names and now getting a result inside the comment field like "3076:1028", the first ID is from the repeater item, the second is for the requested page? Still the same content gets returned. This is how my select field looks in PW wich the above changes: <select id="Inputfield_block_page_repeater3076" class="uk-select" name="block_page_repeater3076" data-action="form-update" data-cache="#Inputfield_comment" data-cache-prefix="3076:" data-update-target="#wrap_Inputfield_block_page_render_repeater3076"><option value=""> </option><option value="1269">GIGASET</option><option value="1220">JESSICA VON BREDOW</option><option value="1167">NINA HEMMER</option><option value="1230">STEFAN KNOPF</option></select>
-
A already disabled ajax loading for the repeater. Than I added your php code to the php file that gets rendered with RuntimeMarkup (block_page.php) and added the js file (block_page.js). Both are loading fine (I testet with console log). But its still not working. I get a error with tracy: PHP Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in .../site/templates/fields/matrixgrid/block_page.php:8 Here is my complete code inside block_page.php (not sure what rentalAdjustmentPage is refering to): <?php namespace ProcessWire; $pageId = $page->id; $adjPageId = $page->rentalAdjustmentPage; $adjParentTitle = $page->parent->title; $bkgPage = wire()->pages->get("title=$adjParentTitle"); $adjTypeId = $bkgPage->comment; if (strpos($adjTypeId, $pageId) == 0) { $adjTypeId = str_replace($pageId . ':', '', $adjTypeId); } $out = wire()->pages->get("id=$adjTypeId")->summary; if ($out) { echo $out; } else { echo wire()->pages->get("id=$adjPageId")->summary; } ?> <a href="<?= $page->block_page->url ?>" class="flex-container overlay-parent"> <img data-src="<?php if($page->block_page->thumbnail) {echo $page->block_page->thumbnail->first()->url();}?>" data-sizes="auto" class="lazyload overlay-bg" /> <h3 class="overlay absolute"> <?= $page->block_page->headline ?> </h3> </a> JS in block_page.js $(document).ready(function () { console.log("Loading is fine") $("[id^='Inputfield_rentalAdjustmentPage_repeater']").each(function (index, element) { var id = $(element).attr("id"); var target = id.replace('Inputfield_rentalAdjustmentPage_repeater', '#wrap_Inputfield_block_page_render_repeater'); var cachePrefix = id.replace('Inputfield_rentalAdjustmentPage_repeater', ''); $(element).attr('data-action', 'form-update'); $(element).attr('data-cache', '#Inputfield_comment'); $(element).attr("data-cache-prefix", cachePrefix + ':'); $(element).attr('data-update-target', target); }); }); Should the selector be like #wrap_Inputfield_block_page_render_repeater or #wrap_Inputfield_block_page_render_repeater3076 with the actual repeater id? Both don't seem to wok for me: var target = id.replace('Inputfield_rentalAdjustmentPage_repeater', '#wrap_Inputfield_block_page_render_repeater'); Not sure where that comment field from you example is living: The code I have (in my context, with 'comment' as the cache field) is :
-
@MarkE Thanks for your help! It's not clear to me where to put the js and php code you posted. Should I put the php inside the template file thats getting rendered with the runtimeMarkup field or in the runtimeMarkup Module file (FieldtypeMarkupRender.module)?
-
My quick test was in JS like this (works outside repeater, but not inside, testet with one repeater item in regular repeater and repeater matrix) $(document).ready(function () { $('.InputfieldPage').attr('data-action', 'form-update'); $('.InputfieldPage').attr('data-update-target', '.InputfieldRuntimeMarkup'); });
-
Hey! Thanks for responding to this! The select field and the runtimeMarkup field are inside the same repeater item. Of course this would not work with multiple repeater items, but if I get it to work with one item I think a can change the code to work with multiple select fields and use the repeater IDs to target each select and runtimeMarkup field.
-
I would love to use this for a page builder module I am working on. My test has a page select field (single) and a runtimeMarkup field assigned to a repeaper matrix type. The console JS logs seem fine, the content inside runtimeMarkup flashes and gets replaced by the same content that was the initialised value, no matter what I select. Do you have any ideas, how I could adapt your code to work inside a repeater?
-
@MarkE this looks interesting. Ajax loading for runtimeMarkup or page fields sounds awesome! I could not get it to work so far. This is the hook called from inside a module. $this->addHookAfter('InputfieldPage::getSelectablePage', function(HookEvent $event) { $InputfieldPage = $event->object; $InputfieldPage->attr('data-action', 'form-update'); $InputfieldPage->attr('data-update-target', '.InputfieldRepeaterItem'); }); I ended up adding the attributes with javascript. $('.InputfieldPage').attr('data-action', 'form-update'); $('.InputfieldPage').attr('data-update-target', '.InputfieldRuntimeMarkup'); This prints to the console when I select a page from the select field. It also seems like the runtimeMarkup field is updating, In the console it shows that the old content is inserted inside runtimeMarkup, so I see a quick update and it returns the same content. Ok it's working fine when I test it on a page! It's not working inside repeater matrix and probably regular repeater fields for me (testet also with only one field populated).
-
EDIT: Turns out it is still working with PW 3.0.144. The error happens when you have two image fields and one of them is empty. I had to make both image fields an array in the settings to solve the error. now everything works as expected. Maybe someone can confirm this bug and make a suggestion how to solve it in the module code?
-
I tried this with PW 3.0.144 and it's not longer working. Showing these errors on the frontend, when a site with an image inside cke is rendered: 2× PHP Notice: Undefined variable: image in .../TextformatterSrcset/TextformatterSrcset.module:178 2× PHP Notice: Trying to get property of non-object in .../TextformatterSrcset/TextformatterSrcset.module:178 1× PHP Notice: Undefined variable: image in .../TextformatterSrcset/TextformatterSrcset.module:182 Any Ideas how to fix this? Would be cool to still be able to use this helpful module
-
Looking at other modules, I think I have to create a process module that would create a page under admin at module install (e.g. admin->setgriddata). The process module would have the code to save the ajax request in the pageTable Item/page. Or is there better way to do this? Sorry for all the noob questions! Iam new to module development ?
-
I found a bug when using this module on a page with a repeater matrix field. After adding a new page from the adminbar, the module redirects to the repeater page that lives under admin->repeaters->repeater-field-name->page instead of the real parent page. A message is shown "This page has no process assigned". However the page gets created under the correct parent page. So just the redirect is wrong. This only happens with the modal option. Can someone confirm this?
-
This is exactly what I want to do ? I will try to do it with ajax, thanks for your suggestions!! Right now Iam busy with other projects, but I will try this as soon as I can get back to it. I will keep you posted.
-
This module is great! It would be nice if there was an option to stay on the edit view after saving a page. Currently the module redirects to the browse view. I had some clients complaining about the redirect as they have to edit long pages and save a lot and than have to constantly click edit again..
-
this looks very promising! Can you give an example on how to render a page reference field with this module. I tried it with this code in the the markup field: <?php // Render for frontend and Backend if($page->block_page) echo "{$page->block_page->render()}"; ?> My template has the block_page as well as the markup field.
-
Hi! Thanks for answering! For my drag/resize page builder module I need simple text fields to store position data for every PageTable item/page (like Y=10 X=6 Width=4 Height=8). I have to change these values dynamically with javascript. Adding these directly to the sub-templates renders them, so they are not accessible with javascript. What do you mean by hidden fields? I could add a field to my main template, where the PageTable lives and store the item positions as one big JSON array. But I would prefer to have the fields added to the sub-templates for the PageTable items/pages, so its easier to output the positions. Iam still very new to module development (this is my first attempt) and not very good with php. So I feel much more comfortable with Javascript/jQuery but Iam learning. I tried to modify the PageTableExtended Module code to add my fields like this (before I added the fields to my sub-templates) <?php foreach($pagesToRender as $p){ $itemID++; $layoutTitle = $p->template->$label ? $p->template->$label : $p->template->name; $ext = "." . $this->config->templateExtension; $template_name = $p->template->altFilename ? basename($p->template->altFilename, $ext) : $p->template->name; $templateFilename = $this->config->paths->templates . $this->pathToTemplates . $template_name . $ext; $parsedTemplate = new TemplateFile($templateFilename); $parsedTemplate->set("page", $p); $parsedTemplate->set("isAdmin", 1); $parsedTemplate->options = array('pageTableExtended' => true); $p->of(true); $iconClass = "fa-angle-down"; $activeClass = "pte-open"; $statusClass = ""; //get input fields for grid item positions (they are part of the sub-template) $data_gs_height = $p->getInputField('data_gs_height'); $data_gs_width = $p->getInputField('data_gs_width'); $data_gs_x = $p->getInputField('data_gs_x'); $data_gs_y = $p->getInputField('data_gs_y'); //how to set input fields for grid based on html data attribut? I would normally do this with JS.. if($p->is(Page::statusUnpublished)) $statusClass .= " pte-unpublished"; if($p->is(Page::statusHidden)) $statusClass .= " pte-hidden"; if($p->is(Page::statusLocked)) $statusClass .= " pte-locked"; if($this->collapseUnpublished && $p->is(Page::statusUnpublished)){ $iconClass = "fa-angle-right"; $activeClass = "hiddenOnStart"; } $layout .= ' <div data-id="item-'.$itemID.'" class="'.$statusClass.' grid-stack-item" data-gs-height="' .$p->data_gs_height. '" data-gs-width="' .$p->data_gs_width. '" data-gs-x="' .$p->data_gs_x. '" data-gs-y="' .$p->data_gs_y. '"> <div class="grid-stack-item-header"> <a href="#" class="toggleRenderedLayout"> <i class="toggle-icon fa '.$iconClass.'"></i> </a> <span class="renderedLayoutTitle '.$activeClass.'">'.$layoutTitle.'</span> <a class="InputfieldPageTableEdit" data-url="./?id='.$p->id.'&modal=1" href="#"> <i class="fa fa-edit"></i> </a> <a class="InputfieldPageTableDelete" href="#"> <i class="fa fa-trash-o"></i> </a> </div> <div class="grid-stack-item-content renderedLayout '.$activeClass.$statusClass.'"> <div class="grid-stack-item-content-inner"> '.$parsedTemplate->render().' <div class="grid-stack-inputs"> '.$data_gs_width->render().' '.$data_gs_height->render().' '.$data_gs_x->render().' '.$data_gs_y->render().' </div> </div> </div> </div>'; } $out = '<div class="grid-stack">'.$layout.'</div>'; ?>
-
Reading the whole thread I now understand that the option to auto select the new page is already implemented. However, for me this is not working. I have the page reference field inside a repeater matrix field. When I create a new page, save and close the modal, the new page is not selected. Is there something that Iam missing? EDIT: It works with page auto complete. This is fine for my use case, but it wasn't clear that ist not working with the other options. Maybe this could be added to the module description.
-
Can someone help me with this? How can I add input fields to the rendered Items that don't get rendered and that i can access with javascript? I need to also save these fields into the database when the page is saved. Would be awesome if someone more experienced could point me in the right direction.
-
I really like this module and it works great. Would it be possible to have an option to create new pages without inserting the title and selecting the template each time? So if I select a template in the field settings and the title field in that template is set to hidden and not required, it would directly open the modal to edit the page, when I click new. Iam currently using a page field in a repeater matrix field to create reusable pages for a certain parent (sort of like how pagetable is doing it natively), but its not intuitive to type in a title and hit publish each time. EDIT: I solved this by changing the setting "name format for children" in the family tab on the parent template (under where the pages are created) and defining a template for the children. That skips the title and template screen, when adding new pages with the page field. Nice! It would be awesome if the new page gets automatically selected after closing the modal. I think that would be more user friendly, because usually you want to select the page you just created right?
-
Hey! Its me again ? Iam currently experimenting with this module, to make the pagetable block items draggable and resizable (with some JS) and output them with CSS Grid. My setup works already, but to save the item positions I need fields to store the data in (like Y=10 X=6 Width=4 Height=8). So my question would be: How can I add fields to the rendered Items that don't get rendered and that i can access with javascript? Changing the module files would be ok. My goal is to make a new inputfield with this, so I made a new version/copy of the Page Table Extended Module. @MadeMyDay I hope it is ok for me to build that on top of this module. Thanks in advance!
-
Nice! Thanks for the quick update! After I updated to the new version, the permission 'trigger-db-backup' wasn't available. I created it manually and now it works. Maybe the permission wasn't created because I updated, rather than installing a new copy? Anyway great update, triggering the backup on login is a nice option!