Jump to content

jploch

Moderators
  • Posts

    427
  • Joined

  • Last visited

  • Days Won

    15

Everything posted by jploch

  1. Hey there, so Im working on this module wich adds css grid drag and drop functionality to a pagetableextended like field and I wonder if the following working approach would cause security issues? I save the positions and dimensions of the pagetable items in one text field (named style) on the page in css syntax (its also easy to save css for different responsive sizes this way using my js code). Now I created a file for my css called style.php: <?php namespace ProcessWire; //in admin page var needs to be set if($isAdmin = $this->page->rootParent->id == 2) { $page = $this->pages->get((int) wire('input')->get('id')); } ?> <style id='pgrid-style'> <?php echo $page->style ?> </style> This is how I include that file in my module for the backend: $this->addHookAfter('Page::render', function($event) { $page = $event->object; $value = $event->return; // Return Content $p = $this->pages->get((int) wire('input')->get('id')); // // include style if page has style field if ($page->process == 'ProcessPageEdit' && count($p->pgrid_style_desktop)) { $dir = dirname(__FILE__); ob_start(); include("$dir/css/style.php"); $contents = ob_get_contents(); ob_end_clean(); $event->return = str_replace("</head>", "\n\t{$contents}</head>", $value); // Return All Changes } }); On frontend in head of main template: <!-- module css--> <?php include($config->paths->site ."modules/PageTableExtendedGrid/css/style.php");?>
  2. Thank you! This looks promising, as I could make the folder name dynamic (it's for a module based on pagetable). However this throws me an error (Method Page::renderBlock does not exist or is not callable in this context) on the frontend and also the page tree in the backend stops working after I insert that hook inside my module inside public function ready()
  3. I can't set a path this way. I think this defines only the name of the template, if I input the path it gets removed after page save.
  4. this is working: <?php echo $item->render($config->paths->templates . "blocks/" .$item->template->name. ".php"); ?> It would be better if I could get the folder of the PageTable settings (the settings where you can specify an alternative folder for your templates) programmatically
  5. Hey folks, I have a question regarding rendering of template files that are in a subfolder of the template folder. How would I for example render these PageTable items, when their template files are inside templates/blocks/: <div class="grid"> <?php foreach($page->grid_ext as $item): ?> <div id="pteg_<?= $item->id ?>"> <?php echo $item->render(); ?> </div> <?php endforeach; ?> </div> I tried this, but get an error: <?php echo $item->render(wire('config')->paths->templates . '/blocks/'); ?>
  6. Thanks @teppo! This was it! I ended up putting my hook inside the Fieldtype Module instead of the Inputfield Module and made the Fieldtype Module autoload with 'autoload' => 'template=admin'. This way the hook works and the Inputfield still seems to be only initialized when the corresponding field is on the page being edited is rendered. Here is my code (adapted from PageTableExtended): <?php namespace ProcessWire; class FieldtypePageTableExtendedGrid extends FieldtypePageTable { public static function getModuleInfo() { return array( 'title' => __('PageTable extended grid'), // Module Title 'summary' => __('Extends PageTable entries for rendering in admin', __FILE__), // Module summary 'version' => 233, 'requires' => array('FieldtypePageTable'), 'installs' => 'InputfieldPageTableExtendedGrid', 'autoload' => 'template=admin', ); } public function init() { parent::init(); } public function ready() { parent::ready(); if ($this->pages->get((int) wire('input')->get('id'))->style) { // add dynamically created styles from field back to document $this->addHookAfter('Page::render', function($event) { $value = $event->return; // Return Content $style = "<style type='text/css' class='pagegrid-styles'> ". $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 }); } } /** * Get the Inputfield used for input by PageTableExtended * * @param Page $page * @param Field $field * @return Inputfield * */ public function getInputfield(Page $page, Field $field) { $inputfield = $this->modules->get('InputfieldPageTableExtendedGrid'); $inputfield->attr('value', $page->getUnformatted($field->name)); return $inputfield; } } Seems to work great, my hook only triggers when the style field is present on the page. Are there any drawbacks to this approach? Would my field still work with frontend editor, when I do 'autoload' => 'template=admin'?
  7. But this would create a <link> element right?
  8. This is probably it. How could I use my hooks in this case? Maybe I should just create another helper module and put the code there, but that would also add more bloat than needed
  9. I tried this with no success: public function ready() { $this->addHookAfter('ProcessPageEdit::buildForm', 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 }); } I know how to add styles and scripts to my module and that is working fine. However to make it work with my dynamically generated styles from Javascript I have to use the method with the style tag.
  10. normal page, where the pagetable is rendered
  11. no luck with this either. I tried inside init and ready function. There seems to be something wrong with how I setup my module, because the hook works inside other modules
  12. I work on a pagebuilder module based on PageTable, for this I need to save dynamically added styles to a field on the page. The styles in the field (field called style) need to be added before page renders. I could add these styles back with JS, but than the page jumps when loading. I could also try to write these styles into a file with javascript, but would like to avoid that complexity and instead add the styles in a <style> tag. Hope that makes sense ?
  13. I already tried that, but no success ? It's strange because the hook works in ready.php or admin.php
  14. 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?
  15. After some testing it turns out that, if the page hosting the repeater has children it is no longer replacing the runtimeMarkup field.
  16. @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..
  17. 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
  18. 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>
  19. 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 :
  20. @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)?
  21. 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'); });
  22. 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.
  23. 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?
  24. @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).
×
×
  • Create New...