Jump to content

Robin S

Members
  • Posts

    5,008
  • Joined

  • Days Won

    333

Everything posted by Robin S

  1. You might find this module useful for that: https://modules.processwire.com/modules/restrict-repeater-matrix/
  2. You could create a Page Reference field that has the Repeater items as selectable pages. Hook for selectable items in /site/ready.php: $wire->addHookAfter('InputfieldPage::getSelectablePages', function(HookEvent $event) { $page = $event->arguments(0); if($event->object->hasField == 'select_repeater_item') { $event->return = $page->repeater; } }); Then create a matrix type that has this Page Reference field. But if the repeater items are to be output among the matrix items then I'm not sure why the repeater exists as a separate field. Wouldn't it be better to just have a matrix field alone and replace the repeater with a matrix type?
  3. Looks good. You could maybe simplify the first hook by using a str_replace(): $wire->addHookAfter('InputfieldPageTable::render', function (HookEvent $event) { $markup = $event->return; $markup = str_replace("&context=PageTable", "&context=PageTable&field_parent={$event->object->hasPage}", $markup); $event->return = $markup; });
  4. Yes, it is about how you build the selector. When you are dealing with input coming from a search form you usually build up the selector in a string variable $selector, adding pieces to $selector for each populated GET variable. But before you try that start with something simpler. Rather than building up a selector string dynamically, experiment with writing out different selector strings and supplying the selector to $pages->find() to see if you get back the pages you expect. The selectors documentation is here: https://processwire.com/docs/selectors/ Each "clause" you add to the selector works with AND logic by default: field_1=foo, field_2=bar This matches pages where field_1=foo AND field_2=bar. For OR logic with different fields and values, check the documentation for OR-groups. (field_1=foo), (field_2=bar) This matches pages where field_1=foo OR field_2=bar. Regarding OR conditions for multiple values in a single field, or multiple fields with a single value, see the following sections: https://processwire.com/docs/selectors/#or-selectors1 https://processwire.com/docs/selectors/#or-selectors2 When you have sorted out what kind of selector you need to match the pages you want you can move on to building up the selector dynamically according to your GET variables.
  5. Like you say, the PageTable page only belongs to the PageTable field when you save it. So you can get the container page as you save the page but not before then. Maybe this post helps: If your PageTable pages are set to be children of the container page it would be easier, but often for PageTable fields that's not the case. It's much easier to get the container page for Repeater fields, so I'd say a Repeater Matrix field is a better choice over a PageTable field for these kinds of things. If you are stuck with the PageTable field and there's no other solution then you could try something like hooking ProcessPageAdd and injecting some JS that checks for an iframe parent and gets the edited page ID from the parent URL, then saves it to a cookie or PHP session via AJAX, then you look for that page ID in the cookie/session in another hook before ProcessPageEdit. But that's hardly a straightforward solution.
  6. I've never needed to use ProcessPageClone but I would have expected the created/modified time to be set to the time the new page is cloned from the old page. Maybe there are use cases for cloning the created/modified times, so perhaps the issue could be a feature request for the option to determine what happens to created/modified times on the cloned page?
  7. Hi @stuartsa, welcome to the PW forums. ? Publishing a new page that is created via the API is not an extra action because pages are published by default. Or more accurately, they are "not unpublished" by default, because being unpublished is an extra status that you may add to a page but is not present by default. When a page is created in the admin via ProcessPageAdd it gets the unpublished status added because the expectation is that the user probably wants to populate some fields in a following step before the page becomes accessible on the front-end, and also because new pages can be added by roles with more restricted permissions than superuser. But when you add pages via the API then you are an unrestricted superuser and so it is up to you to populate the page fields and set page statuses as you see fit. Yes.
  8. Try: $result = new PageArray(); foreach($pages->getById([1049,1053,1055,1059,1152]) as $p) { $result->add($p->repeater_field->findRandom(3)); } $result->shuffle(); // Now do something with $result - foreach, etc.
  9. The status flags are bitwise so if you use a flag value directly to find published pages it would need to be like this: projects_awards.owner.status<2048 But for PageFinder selectors you can use a string for status: projects_awards.owner.status!=unpublished You would also want to exclude unpublished repeater pages because otherwise you can get unfilled "ready" repeater pages in your result. So your selector would be: template=repeater_projects_awards, projects_awards.owner.status!=unpublished, status!=unpublished, include=all
  10. Awesome that you are tackling this, but it goes way over my head I'm afraid so I don't think I'll be much help. I never see any of these gamma correction issues because all my sites use the ImageMagick resizer engine. Which raises the question: does ImageMagick not need gamma correction, or is it just not possible to do gamma correction with IM? Put another way: is the gamma correction a strength or weakness of the GD engine? If the IM engine avoids the gamma correction issue and is generally a better choice for resizing do you think the PW installer should check for IM support and automatically install the IM engine when IM is available?
  11. @SebastianP, give this a try... 1. Remove the "lang_id=18712" portion of the selector string for the autocomplete field. 2. Add the following to the selector string for the autocomplete field: name!=12345 This part of the selector string is deliberately set to something that should always be true - in this case that the page name should not be "12345". The purpose of this is to let us identify the selector when it is sent in the AJAX request. 3. Add the following hook to /site/ready.php: $wire->addHookBefore('ProcessPageSearch::executeFor', function(HookEvent $event) { $input = $event->wire('input'); /// If this request is coming from the autocomplete field... if($input->get('name!') === '12345') { // ...then set the lang_id GET variable $input->get->lang_id = 18712; } });
  12. You still have the "Unpublished" checkbox on the Settings tab and the "Pub" action button in Page List to deal with. Plus to be extra sure you can hook Pages::publishReady to prevent publishing by any means. Some hooks... // Remove publish button and unpublished checkbox in Page Edit $wire->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) { /* @var InputfieldForm $form */ $form = $event->return; /* @var ProcessPageEdit $ppe */ $ppe = $event->object; $page = $ppe->getPage(); // Return early if user is not an agent or it's not a restricted page if(!$event->user->hasRole('agent') || $page->template != 'property') return; // Return early if page is published if(!$page->isUnpublished()) return; // Get status field /* @var InputfieldCheckboxes $status_field */ $status_field = $form->getChildByName('status'); // Remove unpublished checkbox $status_field->removeOption(2048); // Get publish button $publish_button = $form->getChildByName('submit_publish'); // Remove button $form->remove($publish_button); }); // Remove publish button from Page List $wire->addHookAfter('ProcessPageListActions::getExtraActions', function(HookEvent $event) { $page = $event->arguments(0); $extras = $event->return; // Return early if user is not an agent or it's not a restricted page if(!$event->user->hasRole('agent') || $page->template != 'property') return; // Return early if page is published if(!$page->isUnpublished()) return; // Remove publish action unset($extras['pub']); $event->return = $extras; }); // Prevent publishing by any means $pages->addHookAfter('publishReady', function(HookEvent $event) { $page = $event->arguments(0); // Return early if user is not an agent or it's not a restricted page if(!$event->user->hasRole('agent') || $page->template != 'property') return; // Return early if page is published if(!$page->isUnpublished()) return; // Throw exception throw new WireException('You do not have permission to publish this page'); });
  13. @Tom., I tried resizing your original image and could see the banding issue when using GD for image resizing with the default gamma correction. The banding issue doesn't occur when using the ImageMagick resize engine, or when using the GD resize engine if gamma correction is disabled. Disable gamma correction for individual image resize: $page->image->size(1920, 1080, ['defaultGamma' => -1])->url Or disable gamma correction globally in /site/config.php $config->imageSizerOptions('defaultGamma', -1);
  14. Here is a hook method for /site/ready.php that gets the pages that are selected in a given Page Reference field: /** * Get pages selected in a Page Reference field * Use optional argument $options for limiting 'template' and/or 'parent_id', and to 'include_unpublished'. * Usage: $selected_pages = $fields->my_page_field->getSelectedPages(['template' => 'basic_page']); * The number of times each page is selected is available in a custom "occurrunces" property on each selected page. */ $wire->addHookMethod('Field(type=FieldtypePage)::getSelectedPages', function(HookEvent $event) { /* @var Field $field */ $field = $event->object; $options = $event->arguments(0); $get_options = []; if(isset($options['template'])) $get_options['template'] = $this->wire('templates')->get($options['template']); if(isset($options['parent_id'])) $get_options['parent_id'] = (int) $options['parent_id']; $table = $field->getTable(); $query = $this->wire('database')->query("SELECT data FROM $table"); $ids = $query->fetchAll(\PDO::FETCH_COLUMN); $count_values = array_count_values($ids); $items = $this->wire('pages')->getById(array_keys($count_values), $get_options); foreach($items as $item) { if(empty($options['include_unpublished']) && $item->status > Page::statusUnpublished) { $items->remove($item); } else { $item->occurrences = $count_values[$item->id]; } } $event->return = $items; }); The following is an example of how you would get the category pages that are selected in your category field. The number of times each category is selected is available in the custom "occurrences" property if you need it. // Get the selected category pages $selected_categories = $fields->categories->getSelectedPages(); // Demo output foreach($selected_categories as $selected_category) { echo "<p>Category {$selected_category->title} is selected in {$selected_category->occurrences} page(s).</p>"; }
  15. As per my previous reply and the module readme there are config options for dialog width and height. Or maybe I don't understand your question.
  16. Sorry, I didn't understand the original issue properly before. You shouldn't have to activate the tooltip option for the append option to work for selects - I've fixed the logic in v0.1.2 so it should work as expected now.
  17. Excellent tutorial, thanks! Just wondering: why do you write your own str_truncate and textToId functions instead of using core $sanitizer methods like truncate() and name()? (for the latter there are several different sanitizer methods that could be used to get an ID string)
  18. I've added this to v0.1.1. There are data-info attributes on select options - maybe your browser dev tools don't display those attributes for some reason?
  19. No, that isn't possible in this module - the dialog width and height in the module config applies globally to all Hanna tags.
  20. I was going to write a tutorial but then I thought I might as well take the next step and turn it into a module: If @tpr wants to include the functionality in AOS and people would prefer that rather than a standalone module then I'm fine with that. ?
  21. Thanks to @Macrura for the idea behind this module. Page Field Info Adds information about options in Page Reference fields. Supports InputfieldSelect and inputfields that extend InputfieldSelect: InputfieldSelect InputfieldRadios InputfieldSelectMultiple InputfieldCheckboxes InputfieldAsmSelect Requires ProcessWire >= 3.0.61 and AdminThemeUikit. Screenshots Field config Example of changes to inputfield Example of info field filled out in Page Edit Installation Install the Page Field Info module. Configuration In the Input tab of the settings for a Page Reference field... Tick the "Add info tooltips to options" checkbox to enable tooltips for the options in the field. Tooltips are not possible for Select or AsmSelect inputfield types so for those types you would want to tick the next option. Tick the "Append info about selected options" checkbox to append information about the selected options to the bottom of the inputfield. If the Page Reference field is a "multiple pages" field then the info for each selected option will be prefixed with the option label (so the user will know what option each line of info relates to). In the "Info field" dropdown select a text field that will contain information about the page, to be used in the tooltips and appended info. Of course this field should be in the template(s) of the selectable pages for the Page Reference field. Hook In most cases the "Info field" will supply the text for the tooltips and appended info, but for advanced usages you can hookPageFieldInfo::getPageInfo() to return the text. For example: $wire->addHookAfter('PageFieldInfo::getPageInfo', function(HookEvent $event) { $page = $event->arguments(0); // The page $inputfield = $event->arguments(1); // InputfieldPage $field = $event->arguments(2); // The Page Reference field $info = $event->return; // Text from the info field, if any // Set some custom text as the $event->return... }); https://github.com/Toutouwai/PageFieldInfo https://modules.processwire.com/modules/page-field-info/
  22. A couple of things to check: That you are calling the endpoint URL with/without a trailing slash according to the template "Should page URLs end with a slash?" setting. If the site is multi-language that you are calling the endpoint URL with the language string in it, e.g. http://site/en/subscription-new/
  23. It tells PW that there is more than one OR-group in the selector string. It's all about specifying what has to match in order for the whole selector string to match - remember that for every OR-group only one selector in the group has to match. So previously you were doing this... // Templates $selector = "(template=home|basic-page|product-category, status!=hidden), (template=news-item|product-page)"; // Fields $selector .= ", (title|headline|lead|body%=$q), (content_matrix.columns.body%=$q, content_matrix.columns.count>0)"; ...which we can represent as this... // Templates $selector = "(template selector 1), (template selector 2)"; // Fields $selector .= ", (field selector 1), (field selector 2)"; ...and it is the same thing as... // Templates $selector = "foo=(template selector 1), foo=(template selector 2)"; // Fields $selector .= ", foo=(field selector 1), foo=(field selector 2)"; ...which is saying "find any pages that match template selector 1 OR template selector 2 OR field selector 1 OR field selector 2". So this will match a lot of pages that you don't actually want to match. Whereas this... // Templates $selector = "foo=(template selector 1), foo=(template selector 2)"; // Fields $selector .= ", bar=(field selector 1), bar=(field selector 2)"; ...is saying "find any pages that match (template selector 1 OR template selector 2) AND (field selector 1 OR field selector 2)".
  24. Hi @Rhen GWL and welcome to the PW forums. By any chance do you have the template setting "Should page URLs end with a slash?" set to "No"? There seems to be an issue with the default action of the comments form that will submit the form to the parent page if the current page has no trailing slash. I opened a GitHub issue here, and in the meantime until Ryan responds you can override the default form action in the $options array for renderForm(): echo $page->comments->renderForm(array('attrs' => array('action' => $page->url)));
  25. There are predefined system permissions for this - you just have to install them: https://processwire.com/docs/user-access/permissions/#page-edit-created https://processwire.com/docs/user-access/permissions/#page-edit-trash-created
×
×
  • Create New...