-
Posts
726 -
Joined
-
Last visited
-
Days Won
3
Everything posted by froot
-
I'm having some difficulties understanding how this works and getting started. So I installed Vue JS inside a folder in /site/templates/scripts/vue/ created a vue app inside of that folder and did vue add vuetify I followed the instructions in the official vuetify guide and did a npm run build Anyways, I miss the part where I include the vuetify .css and .js files in the <head> or <body> tag respectively. Which files do I need to include?
-
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
thanks @LMD for your feedback, yes I assumed there must be a lot of overhead in my code the way it is now. I will update it soon to use SQL commands and update it probably again once meta is accessible via selectors. -
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
thanks @bernhard, yes I noticed that later on. I managed to get the module to serve my needs, it's here: https://github.com/dtjngl/MenuAllocator I (re)watched your hook-tutorial, it's interesting but I doubt it can help me in this very use-case since I do not really populate fields on the page and the fields in question are rendered at runtime (by a another hook), so I had a hard time saving the values to the page (luckily there's ->meta). I'm not sure if this is the best approach but it works. @everyone, please give it a try, I'd love to get feedback. -
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
public function ready() { $this->addHookAfter('ProcessPageEdit::buildFormContent', $this, 'addCustomFieldToPageEditForm'); // ... } public function addCustomFieldToPageEditForm(HookEvent $event) { $page = $event->arguments('page'); // null // ... } ;( EDIT: $id = $this->input->get('id'); // frontend page object id $page = wire('pages')->get($id); // frontend page object ? -
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
doesn't work ? should be so easy though, right? class MenuAllocator extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Menu Allocator', 'version' => 1, 'summary' => 'A module to allocate menus to pages.', 'autoload' => 'template=admin', ); } public function ready() { // Add a hook to build the page edit form content $this->addHookAfter('ProcessPageEdit::buildFormContent', $this, 'addCustomFieldToPageEditForm'); // Add a hook to process the form input when the page is saved $this->addHookBefore('Pages::saveReady', $this, 'saveCustomField'); } public function init() { bd($this->meta); } public function addCustomFieldToPageEditForm(HookEvent $event) { $form = $event->return; // Check if this is a frontend page (you can define your criteria here) if (strpos($this->input->url, '/admin/') !== false) { // Create the custom field as an InputfieldText $field = $this->modules->get('InputfieldText'); $field->name = 'custom_text_field'; // Use a different name for rendering $field->label = 'Custom Field for Display'; // Different label for rendering $field->description = 'Enter a custom value for this page (display only).'; // Add the field to the page edit form $form->add($field); } } public function saveCustomField(HookEvent $event) { // Get the page object from ProcessWire's API $page = wire('page'); // Check if the page object exists if ($page instanceof Page) { // Get the custom_text_field value from the form input $fieldValue = $this->input->post->custom_text_field; // Use the correct field name // Set the custom field value to the page's meta data $page->meta->set('custom_text_field', $fieldValue); // Use the correct field name for meta data } } } -
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
I can try that, I'm just trying to understand why my approach doesn't work. Why does a similar logic work for editing templates but not for editing pages? -
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
in the module or module config/settings, I want to define an array of "menus". Then, on every page in the page tree, except on pages inside "Admin", I want to render an array of checkboxes (InputFieldCheckboxes), one for each entry in the predefined "menus"-array. When the content manager edits a page they will see these checkboxes, and one or more before saving the page will naturally be saved somewhere, ideally as a property of the page. When creating the menus in the markup (e.g. top menu, footer, sidebar, you name it), one should be able to select the pages according to the values set for said field on the pages. I'm not sure if creating adding a field and adding it to a fieldgroup and template is necessary (also this approach is quite prone to errors, I have to consider __install() and __uninstall() etc.), I managed to accomplish something very simliar with a different module (https://github.com/dtjngl/simpleSearch/blob/main/SimpleSearch.module.php), the difference was, that one renders a text field on each template and when editing a template, the entered value gets saved to the template object. Works like a charm. Thanks for you input! -
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
public function saveCustomField(HookEvent $event) { $fieldValue = $this->input->post->menus; bd($fieldValue); ... $page->set('menus', $fieldValue); } the fieldValue is null when no checkbox is ticked, if first checkbox is ticked it stores an array like so: array (0 => 'top') which is what I expect. My guess is one of the following - I cannot pass just pass an array to a $page->set() method - I misconfigured the hooks - Since I hook a function and edit the saved value I need to return the edited object - I cannot save the value to the page cause the field does not actually live on the page - something about the InputFieldCheckboxes API that works entirely different -
Checkbox Values Not Saving in Custom Module
froot replied to froot's topic in Module/Plugin Development
Thanks @Mike-it for your suggestion! Before I continue I would like to understand one thing. Is it even possible to render a field on the page-edit page and save its value to the page? As to my understanding it should, because a page is an object and I can add properties to a page object with code as well, so why not with the UI? Or do I need to, upon installing the module, create a field, add it to a fieldgroup and a template and, optionally, remove it accordingly when uninstalling? -
Hello everyone, I'm working on a custom ProcessWire module, and I've encountered an issue with checkbox values. The checkboxes render correctly in the page edit form, but when I tick them, save the page, and then reload it, the selected values are not saved to the page. I've tried various approaches, including hooks, to ensure that the selected values persist in the database, but so far, I haven't been successful. I'm seeking advice and solutions to resolve this issue and ensure that the checkbox values are properly saved when a page is edited. Any help or suggestions would be greatly appreciated! Thanks in advance! I wish you a nice Sunday otherwise. class MenuAllocator extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Menu Allocator', 'version' => 1, 'summary' => 'A module to add a custom field to page edit forms.', 'autoload' => 'template=admin', ); } public function __construct() { $menuAllocatorSettings = wire('modules')->getConfig($this); foreach ($menuAllocatorSettings as $key => $value) { $this->$key = $value; } } public function init() { // Add a hook to build the page edit form $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addCustomFieldToPageEditForm'); // Add a hook to save the field value when the page is saved $this->addHookBefore('Pages::executeSave', $this, 'saveCustomField'); } public function addCustomFieldToPageEditForm(HookEvent $event) { $this->message('this is addCustomFieldToPageEditForm'); $page = $event->object->getPage(); // Check if this is a frontend page (you can define your criteria here) if (strpos($page->path, '/admin/') !== 0) { // Get the selected menu names from the module's settings $menuNames = $this->menus; if ($menuNames == '') return; $menuNames = explode(' ', $menuNames); // Create the custom field as an InputfieldAsmSelect $field = $this->modules->get('InputfieldCheckboxes'); $field->name = 'menus'; $field->label = 'Menus'; $field->description = 'Select menu names for the page.'; // Add menu options based on module configuration foreach ($menuNames as $menuName) { $field->addOption($menuName, $menuName); } // Add the field to the page edit form $form = $event->return; $form->insertBefore($field, $form->getChildByName('title')); // Adjust the position as needed } } public function saveCustomField(HookEvent $event) { $page = $event->arguments[0]; // Check if this is a frontend page (you can define your criteria here) if (strpos($page->path, '/admin/') !== 0) { // Get the field value from the input $fieldValue = $this->input->post->menus; // Use the correct field name $this->message($fieldValue); // Save the field value to the page $page->set('menus', $fieldValue); // Use the correct field name } } }
-
I think it had to do with when the page loads. Running the above function later than in init() workes as expected, there doesn't even seem to be a need for the API calls that target the specific language value, PW does that automatically with the selector after all ^^ However, here's a very similar requirement, therefor I use the same thread to discuss it. class MyModuleConfig extends ModuleConfig { public function getInputfields() { $inputfields = parent::getInputfields(); $f = $this->modules->get('InputfieldText'); $f->attr('name', 'foo'); $f->useLanguages = true; // This enables multilingual support $f->columnWidth = 100; $inputfields->add($f); return $inputfields; } } class MyModule extends WireData implements Module, ConfigurableModule { public function bar() { $foo = $this->foo; echo $foo; // always returns the default language of the page, not even } } I'm able to create a multilanguage field in the module's settings but I am not able to return the page language specific value in the frontend. What am I doing wrong? Thanks for your help again. P.S. I hope you're enjoying your summer so far.
-
OK, after further investigation, I think the real and more technical question I should ask is, how do I access the current $page from inside the module? Do I need to pass it? like: // on Test Page $MyModule = $modules->get('MyModule'); $MyModule->renderPageTitle($page); // Test Page // inside the module class MyModule extends WireData implements Module, ConfigurableModule { ... public function renderPageTitle($page) { echo $page->title; } ... } I am extending class WireData, don't know if that makes a difference.
-
Hello everyone, I'm currently facing a perplexing issue with the search functionality on my PW website. The search results are exhibiting inconsistency, producing both false positives and false negatives, depending on the code approach and if-condition used. Problem Description: When performing a search for a specific term, the condition used to determine if a search result matches the query seems to act binary, leading to two distinct issues: False Positives: At times, matches are found in languages other than the one specified, leading to incorrect results. For example, English words may appear in search results on the German site, and vice versa. False Negatives: Conversely, in some cases, no matches are found even when they should be present, i.e. the condition I set is never met, regardless of the site's language. Approaches Tried: isTranslatable() Method: Initially, I attempted to check if the field was translatable and, if so, used the getLanguageValue() method to fetch content in the user's language. Unfortunately, this approach introduced the aforementioned false positives and false negatives. getUnformatted() Method: In an effort to mitigate the inconsistency, I explored using the getUnformatted() method, which should return all language versions of the field value. However, this approach also resulted in the same issues. protected function filterCurrentLanguage($items, $q) { $language = $this->wire('user')->language; // always seems to return the same ID, logged in and incognito :( $filteredItems = new PageArray; foreach ($items as $item) { $fields = $this->getUniqueFieldsFromTemplate($item->template); $foundInCurrentLanguage = false; foreach ($fields as $field) { // Here lies the condition that seems to behave inconsistently $fieldValue = $item->getLanguageValue($language, $field); if (stripos($fieldValue, $q) !== false) { $foundInCurrentLanguage = true; break; } } if ($foundInCurrentLanguage) { $filteredItems->add($item); } } return $filteredItems; } Unfortunately, I cannot utilise a selector for my language-specific queries, which may have limited the available solutions. I am open to exploring other possible approaches or features that might be added to the ProcessWire API in future versions, if any, to facilitate better language-specific search filtering. I am seeking insights from the ProcessWire community to understand why the condition behaves in this inconsistent manner. Additionally, I would greatly appreciate any guidance or alternative approaches that can help me improve the search functionality, ensuring that it provides accurate and language-specific search results. If anyone has faced a similar challenge or possesses expertise in handling language-specific search and filtering in ProcessWire, I humbly request your assistance and valuable input. Thanks a lot!
-
OK I figured it out. It appears that when I render the results, I need to amend the selector's start and limit, but when I render the pager, I cannot do that, I need to use the methods ->setStart() and ->setLimit() I need to remember to not mix this up in the future.
-
I'm trying to build a search module. See my rep here https://github.com/dtjngl/simpleSearch.git Once installed, you should be able to test it, just make sure you adjust $this->indexedCategories in the module's init() function. (I will change this later to be defined in the module's config file instead.) Then use the public functions to render the different parts of the search page: echo '<div id="filters">'; echo $simpleSearch->renderFilters(); echo '</div>'; echo '<div id="criteria">'; echo $simpleSearch->renderCriteriaMarkup(); echo '</div>'; echo '<div id="paginationstring">'; echo $simpleSearch->renderPaginationString(); echo '</div>'; echo '<div id="overview">'; echo $simpleSearch->renderOverviewMarkup(); echo '</div>'; echo '<div id="search-results">'; echo $simpleSearch->renderResultsMarkup(); echo '</div>'; echo '<div id="pagination">'; echo $simpleSearch->renderPaginationMarkup(); echo '</div>'; The problem with the pagination: $this->renderResultsMarkup() the entries seem to paginate alright $this->renderPaginationString() the entries seem to paginate alright $this->renderPaginationMarkup() pagination links DON'T show up at all! I don't know what I'm still not getting about pagination and what I'm doing wrong. When do I fetch and where do I store all the results? And at which point do I paginate the results? It just never makes sense to me. Any help and advice is much appreciated.
-
to set all the "backlinks" programmatically, i.e. set all the referenced pages to point back, shouldn't something like this work too? $projects = $pages("template=project"); foreach ($projects as $project) { // related_pages being the name of the page reference field // I store the value of the page reference field temporarily in a variable $temp = $project->related_pages; $idle = new WireArray; // populate the page reference field with an empty WireArray object and save it $project->of(false); $project->related_pages = $idle; $project->save('related_pages'); $project->of(true); // populate the page reference field with the value we stored in $idle $project->of(false); $project->related_pages = $temp; $project->save('related_pages'); $project->of(true); } Because as I understand it, the value needs to change and the page needs to be saved for the module to do what it does. Doesn't work though…
-
I know a media_manager_image field is always an array so I need to loop through it. But can I access a specific image given the key? I tried: $image = $page->mmfield[3]; $image = $page->mmfield->get(3); $image = $page->mmfield->eq(3); none of those work ;(
-
@kongondo I have some images that use a different caption depending on the page they appear on. Can you think of a solution for this? EDIT: I was thinking, in order to accomplish this, maybe I can add a text field next to the image that I want to use that, if populated, would override the image caption. But, since I use many images on one page, I would need to have a text field like that on the page template the image appears on (not on the media-manager-image template), and also one for each image to make this work, thus also need multiple media manager image fields on one page. Therefore, here's my other question: Would it be possible to use a media manager image field inside a repeater field or repeater matrix field?
-
access the description field of an image (media manager)
froot replied to froot's topic in API & Templates
OK I figured it out. $images = $pages("template=media-manager-image, include=all"); foreach ($images as $image) { $preview = $image->preview; $description = $image->media_manager_image->first()->description; if ($preview != '') { $image->of(false); $image->media_manager_image->first()->description = $preview; $image->save(); $image->of(true); } } -
access the description field of an image (media manager)
froot replied to froot's topic in API & Templates
after a bit of more investigation I was able to get rid of the warnings yet output the preview an description alright. However, cannot seem to set the values for the images… $images = $pages("template=media-manager-image, include=all, id=3102"); foreach ($images as $image) { foreach($image as $ii) { $image->of(false); if (gettype($ii) != "object" || gettype($ii->first) != "object") { continue; } $ii->first->description = $image->preview; foreach ($ii as $iii) { $item = $iii; } $image->save($iii); $image->of(true); } } Please help! ? -
I have added a preview field to the media-manager-image template which I populated on many pages. Then I realised that there's a description field in each image anyway. Now I want to populate the description field with the value from the preview fields. (I could also set the description field directly with the CSV file that I used for the preview field, but…) …first want to see if I can access the field(s) alright. Then I would try to set populate the fields and save the pages. Here's my code so far: $images = $pages("template=media-manager-image, include=all"); foreach ($images as $image) { echo 'ID: ' . $image->id; echo '<br>'; echo 'PREVIEW: ' . $image->preview; echo '<br>'; foreach($image as $ii) { if ($ii) { // cause I keep getting warnings... foreach ($ii as $iii) { echo 'DESCRIPTION: ' . $iii['description']; echo '<br>'; } } } echo '<hr>'; } with the above code, I pretty much get what I want but a lot of warnings: PHP Warning: foreach() argument must be of type array|object, int given PHP Warning: foreach() argument must be of type array|object, string given How can I bail out of those warnings?
-
what would be very handy is to see in the media-manager field (on a page) as well as in the media manager itself: - the ID of the file/image - the title of the file/image (I can see the name, description, tags but no title) - not just how often but where on which page(s) it was used! (and maybe an edit-link to those pages??) Plus when I have an image in front of me, either in the media-manager field on a page or in the media-manager, I cannot edit see the description field. I can click on "Edit" (on the image) which opens a dialogue. There I can edit title, name and the file itself but not the description. I have to click on "Edit" (on the image) again to open another dialogue inside the dialogue to edit the description and tags. This is not a big deal, just wanted to mention that it doesn't say description anywhere around the field so someone might be confused. Concerning my requirement of searching an image by the page(s) it appears in, I thought of a maybe feasible solution. How about you can search an image by tags and then upon saving a page, add the title of the page as a tag to the image and of course remove the tag when removing the image from a page? EDIT: OK that last part is maybe too ambitious
-
how can I retrieve the URL (absolute path) of an image added to a media-manager-image field of a page? Can't find the API. EDIT: never mind, I figured it out, need to loop even though it's a single image. foreach ($page->mmfield as $image) { echo $image->media->url; } right?
-
sorry, me again, I hope you appreciate the feedback. In an upcoming version, could you add the page-ID of the image when listing (or detail view) of an image in the MM? I can see title, name, dimensions, filesize, tags, … but no ID.
-
I tried this approach but I get Value set to field 'mema_images' must be a MediaManagerArray (mema_images being the field of type "MediaManager" on the template for the pages where I want to "add" images or technically speaking refer to the image-pages)