Jump to content

Search the Community

Showing results for tags 'Hooks'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. Hello forum! I've yet again stumbled on a head-scratching situation. We have enabled the option on our articles template and events template that it skips the title adding part and goes straight to the form. This is what our customer wants. So when you add a new article or event it automatically names it temporary to "article-0000000" and same with event. Now the problem is that obviously after saving the form we want to change to page url or "name" to the title, like it's normally. Now here's the code for the hook: wire()->addHookBefore("Pages::saved(template=tapahtuma|artikkeli)", function($hook) { $page = $hook->arguments(0); $newUrl = wire()->sanitizer->pageName($page->title); // give it a name used in the url for the page wire()->log->message($page->name); $page->setAndSave('name', $newUrl); }); I get the correct page and the name and path changes when I log them, but when I try to save it. It just loads and then I get: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) This happens in sanitizer.php and then another error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0 What is happening? Am I not suppose to use sanitizer in this way? When we made a temporary page object in out other hook, the sanitizer worked perfectly. Thanks for the help!
  2. Hello forum! I'm trying to learn how to time up my functions by using lazycron but I can't get it fired up. Here's my code in site/init.php: function setEventToRepeat(HookEvent $e) { $wire->log->message("kutsutaan cron"); $events = $wire->pages->find('template=tapahtuma'); die(var_dump($events)); $wire->log->message('Kaikki tapahtumat haettu:' .$events); } $wire->addHook('LazyCron::every30Seconds', null, 'setEventToRepeat'); I get nothing in the logs and can't echo or dump anything Thanks for the help!
  3. So I have been diving into hooks lately, and I am enjoying them thus far. However, I guess I am a bit stumped on how to achieve what I want too. I am trying to set up a hook that would create a new child page when the parent page is saved. However, when you save the parent page a second time, I just need to update the child page without creating multiple child pages. What would be the best way to go about this? So after rereading my post, I believe it is a bit vague so I will try to explain more. The Goal: Create a page with a template "one". Once the page is created/saved => create a new child page with the template of "two" If the parent is saved anytime after, do nothing to the child page (limit the parent page to one child page) The parent page is really just being used to output content, whereas the child page is being used to pull out the some fields from the parent to be used elsewhere. I might have made this too complicated in my head.
  4. Hi Guys, I am running a page template that contains a filter form that allows users to display results based on number of comments. Here is what I am thinking about doing: -add new field called total_comments -somehow populate this field every time a new comment is added or removed by admin with count($page->comments) -use form filter to display results that the selector form has found. Example: $selector = “total_comments>=$q”; My question to everyone: Is this a good approach? If so how do I get another field to update based on the comment module adding or removing a comment?
  5. I got a field with a type of "files" named: course_file .. how can I upload it to custom directory??
  6. $this->addHookBefore('InputfieldTextarea::render', function($event) { $field = $event->object; if($field->name == 'body_offer') { $del = ''; foreach($this->wire->pages->get(11229)->textblocks as $item) { $field->entityEncodeText = false; $body = str_replace(PHP_EOL, '', $item->body); $body = addslashes($body); $title = $item->title; $field->description .= $del . "<a href=\"#\" class=\"ckesnippet\" data-snippet=\"$body\">$title</a>"; $del = ' | '; } } $js = wire('config')->urls->templates . 'scripts/ckesnippets.js'; $event->return = str_replace("</html>", "\n<script type='text/javascript' src='$js'></script>\n</html>", $event->return); }); I'm trying to add custom text-blocks from repeater fields into CKEditor. I've stolen the whole idea (and code) from @bernhard Problem is: The links are actually being rendered, but the Javascript is not loaded, i.e. the $event->return line doesn't seem to work. If I inspect the HTML, my additional script-tag is nowhere to be seen. I don't get any errors either. Running latest PW dev + PHP 7.1.19.
  7. Hi all, I am using the formSubmitSuccess form builder hook to send a copy of the form submission to a third party. However I couldn't figure out how to get the submissions form type at this point, the reason being is that I only want to send the data onto the third party for certain form types. I don't have the submission details being passed into the hook, wasn't sure how to achieve this so at the moment I have it doing a DB query to pull the latest submission details for that form type so I'm rather stumped about how I can go about achieving this. Hope thats makes sense.
  8. Hi there, I'm trying to limit a specific user can only add pages as a child (under) a page created by themselves. The discussion in this thread gets close, it's a working solution on how to only allow editing on pages you created yourself. I'm using this and it works well. But I'm not sure how to modify this for my purposes. I'm suspecting I need to do to something like $this->addHookBefore("Page::added", $this, 'added'); then in "added" check if parent is created by the current user. But I'm a bit lost on how exactly to do this. thank you! /J
  9. Sometimes I need pages in the site tree that are basically just a reference to another page – to redirect to the original page or display the same content under the new page url. I was surprised I couldn't find anything like that in the forum or as a module already. However, there is a new module by @Robin S but not exactly what I need. Example Home News Press Newsroom Media Services About Newsroom (virtual page for /news/newsroom/) Contact Example I: The page /about/newsroom/ should act as /news/newsroom/ – so, wehen I loop all pages for a sitemap both pages should have the URL /news/newsroom/. Example II: Another example (not often used) would be tu display the exact same content on /about/newsroom/ – although the page itself has no content on its own. Those examples don't have much in common, but they are just virtual or fake pages in the site tree. While the second one should be an easy task with wireRenderFile(), the first example isn't quite obvious to me. I think I have to use hooks and I have no idea where to start. I really appreciate you guys come up with a solution for everything, but I need to learn this myself So just some hints to start would be great! Do I put the code into a module or some of the _init.php, ready.php etc. files? Or do I have to use a template file (e.g. virtual-page.php)? When I look into Captain Hook – how do I find the appropriate point to hook into? (/wire/core/ Page.php and loaded()?) Do I need to create/manipulate each field separately (path, title, summary)? Sorry for the long read
  10. Hey guys, i have some sort of events/campaigns which have a lifespan. To deactivate them i made a checkbox-field called closed and i have to deactivate them manually. I would like to put two fields in the template, startdate and enddate, which activate/deactivate that checkbox field automatically. Dou you have any idea how to bring that on the run?
  11. I want to remove "Breadcrumbs" From Some Admin Pages .. for example (Modules/Profile) Pages. Aslo: How To Modify Page Headline .. Thanks .
  12. Hi Everyone, I have built until now two websites using ProcessWire & it's really powerful- the only thing that seems blurry to me is Hooks not as a concept, but i don't know which one to choose and when ?? For example, i tried to change to login redirect URL : So why choosing "___loginSuccess" over "___afterLogin" ? There is a lack of tutorials related to this topic / and docs too
  13. How can I override the url method to add an extra get parameter to each address? Ex: About page url /about/ like this /about/?param=2
  14. I have a hook that creates a page for a subset of the pages on our site. It uses the saved page's name as part of the created page's name. The problem I am having is that my hook, attached to Pages::saved(), is being called even when the page save failed because of missing fields. Is there a way I can tell that the page save failed due to missing fields? Never mind - it does succeed; it just issues warnings about required fields.
  15. Hello, I noticed that the Pages::added hook gets called twice. PW 3.0.62. To test , add this to admin.php wire()->addHookAfter('Pages::added', function($event) { bardump('added'); // needs Tracy Debugger }); Can anyone confirm this? It gives me trouble when adding a hook that skips the page add step (for users), following Pete's concept. There will always be created 2 new pages which I need to avoid. Is it a feature or a bug?
  16. I have a Page Table field that, for new entries, I want to construct the name for. When I click the Add New button the page being added has already been given a random name like: 20170422-003744. I wish to 1) change that name so it's obvious it is a temporary name and 2) when either Publish or Save + Keep Unpublished is clicked, set the name of the page based on the content entered. What hooks can I use to accomplish 1 and 2? thanks.
  17. So I discovered in this topic ( ) that I can cancel all hooks after my own hook. Now I want something like that. I want my hook which is called on page render to cancel all other events, also the after page render and the before page render methods, is this possible? This only need to be done when some conditions are met. /** method replaces original page::render method and is called with hook priority one */ method onPageRender (HookEvent $event) { if (my condition is true) { $this->cancelHooks = true; // to cancel all hooks to page::render // how to cancel after Page::render events // how to cancel before Page::render events } } Is this possible at all?
  18. I have created a hook with priority one because I want it to run asap. Now I want this same hook to prevent all other hooks from running, is this possible, if so, how can I achieve that? For example, normally hooks would run like this: hook 1 -> hook 2 -> hook 3 -> hook 4 -> etc. Now I want it like this: hook 1 -> hook 2 -> hook 3 -> hook 4 -> etc.
  19. Hello, I am still learning ProcessWire. I am trying to hook a method in ListProConfig.php. After the processInput method is called I would like to know the user id of the person that called the method, the page name that was involved in changed lister settings, and then get the new settings. I am having problems getting my hook to work. In the init of my module I have the following code: wire()->addHook("ListerProConfig::processInput", function($event){ $this->wire('log')->save('stephen_ext',"Someone called processInput"); }); Even though I know that processInput is called I never get anything written to my log.
  20. Hi Guys This hook works fine. $this->addHookAfter('Pages::saveReady', $this, 'hookIndexingBefore'); protected function hookIndexingBefore( HookEvent $event ) { $page = $event->arguments("page"); if(!$page->template->hasField("index")) return; // no index field in this page/template if($page->isNew() || $page->isTrash() || $page->indexSaveFlag) return; $language = $this->wire("user")->language; // save user lang $page->index = ''; foreach($this->wire("languages") as $lang) { $this->wire("user")->language = $lang; // change user lang wire('pages')->setOutputFormatting(true); $content = $page->render(); // render page and get the content wire('pages')->setOutputFormatting(false); if($content) $content = $this->parseContent($content); //remove html, new lines etc... $page->index .= $content; } $page->indexSaveFlag = true; // in case it get's saved again (not case with Pages::saveReady) $this->wire("user")->language = $language; // restore user language } But when I try to save a page per api I get an Internal Server Error 500. When I replace "$page->render();" with "" inside the hook, it doesn't cause a internal server error anymore. $page->save(); //causes internal server error now
  21. Hi, I've created a simple module that does the following: Checks if a checkbox is ticked ('media_wall_quote_hero') on a page using the template 'media_wall_quote'. If that checkbox is ticked, it adds that page to a PageTable field ('quotes_hero') located on the 'home' template. If it's not checked and the page is in the PageTable field it is removed. It all works correctly when checking/unchecking the box on pages using the 'media_wall_quote' template in admin. However, if I edit the pages in the PageTable field itself on the homepage in admin, when I save the modal, the PageTable field is not updated. Strangely if I uncheck it (ie. when it should be removed) the PageTable field says 'item added'. Is there a way I can hook into the PageTable field when the modal is saved and update it so if I check/uncheck the box it does the correct action? public function init() { $this->pages->addHookAfter('save', $this, 'AddRemoveHeroQuotes'); } public function AddRemoveHeroQuotes($event) { $page = $event->arguments(0); if($page->template == 'media_wall_quote') { $home = wire('pages')->get(1); $home->of(false); $work_page = wire('pages')->get("template=work, media_wall_work=$page"); // If this quote is a (published) hero quote add it to the pagetable field if($page->media_wall_quote_hero == 1 && !$page->is(Page::statusUnpublished)) { if(!$home->quotes_hero->has($page)) { $home->quotes_hero->add($page); } } // If this quote is a not a hero quote or is unpublished remove if from the pagetable field elseif($page->template == 'media_wall_quote' && $page->media_wall_quote_hero == 0 || $page->template == 'media_wall_quote' && $page->is(Page::statusUnpublished)) { if($home->quotes_hero->has($page)) { $home->quotes_hero->remove($page); $this->message('removed'); } } $home->save('quotes_hero'); } }
  22. For some reason when I unpublish an already-published page, even of a template other than the specified 'importer', all its fields are cleared on page render. How do I understand and remedy this? Peace & thanks public function init() { $this->addHookAfter('Page::render', $this, 'renderEditor'); } protected function renderEditor(HookEvent $event) { $here = $event->object; $page = $this->pages->get($this->input->get->id); //$this->log->message($page->template.$here->process); return; if ($here->process != 'ProcessPageEdit' && $page->template != 'importer') return; $css = $this->config->urls->ProcessImportAll . 'ass/ProcessPageEdit_importer.css'; $event->return = str_replace("</head>", "<link rel='stylesheet' type='text/css' href='{$css}'/>\n</head>", $event->return); $field = wire('fields')->get('name=pi_template'); if (count($field->templateTypes)>0) { $templates = $field->templateTypes; } else { $templates = []; foreach (wire('templates') as $tpl) $templates[] = $tpl->id; } sort($templates); //$tplTypes = json_encode($templates); $templatesFields = $this->getTemplatesFields($templates); $templatesFields = json_encode($templatesFields); $js = <<<EOT <script> $(document).ready(function(){ if (!document.getElementById('Inputfield_status_2048').checked) { $('#ProcessPageEditContent *').prop('disabled',true); } else { var all = $templatesFields; var sel = '#Inputfield_pi_template option[selected="selected"]'; var tpl = getTpl(); var arr = all[tpl]; var def = '<option value=""></option>'; $('#Inputfield_pi_match').prepend(def); filterFields(tpl); $('#wrap_Inputfield_pi_template .asmListItem .asmListItemRemove').click(clearFieldOptions); $('#Inputfield_pi_template').change(function() { var on = $(this).find('option[selected="selected"]')[0]; if (on !== undefined) { tpl = on.value; //console.log('clicked ' + tpl); filterFields(tpl); } else { tpl = null; clearFieldOptions(); } }); function filterFields(t) { if (t != null) { $('#Inputfield_pi_match').prop('disabled',false); arr = all[t]; //console.log(arr); $('#Inputfield_pi_match option').each(templateFieldOptions); $('#wrap_Inputfield_pi_fieldmap select option').each(templateFieldOptions); $('#_Inputfield_pi_maptab').click(function() { //$('#wrap_Inputfield_iu_fieldmap select option').each(templateFieldOptions); }); } else { clearFieldOptions(); } } function getTpl() { if ($(sel).length>0 && $(sel)[0].value) { var tpl = $(sel)[0].value; } else { var tpl = null; } return tpl; } function templateFieldOptions() { var val = parseInt(this.value); if (!arr.includes(val) && val>0) { //console.log(val + ' ' + arr); $(this).prop('selected',false); $(this).prop('disabled',true); } else { if (arr.includes(val) && val>0) { //console.log(tpl); $(this).prop('disabled',false); } } } function clearFieldOptions() { $('#Inputfield_pi_match').find('option[value=""]').first().prop('selected',true); $('#Inputfield_pi_match').find('option[value!=""]').each(function() { $(this).prop('disabled',true); }); $('#Inputfield_pi_match').prop('disabled',true); $('#wrap_Inputfield_pi_fieldmap select').find('option[value=""]').first().prop('selected',true); $('#wrap_Inputfield_pi_fieldmap select').find('option[value!=""]').each(function() { $(this).prop('disabled',true); }); $('#wrap_Inputfield_pi_fieldmap select').prop('disabled',true); } } }); </script> EOT; $event->return = str_replace("</body>", "$js</body>", $event->return); //$this->filterFieldFields($event); }
  23. I have a module with 'autoload' => 'template=admin'. I need to hook into ProcessPageEdit for editing template=importupdate, and within my hook function add CSS and JS files. I have: public function init() { $this->addHookAfter('ProcessPageEdit::execute', $this, 'addlStyles'); } private function addlStyles(HookEvent $event) { //$page = $event->arguments(0); if($page->template != 'importupdate') return; $css = wire('config')->urls->modules . 'ImportUpdateUltimate/editImportUpdate.css'; $this->config->styles->add($css); } which does nothing.
  24. Hi, I'm about to implement a multisite project with PW3 (which is great btw!!!). Because of "reasons" I need to implement my own routing. To do this I implemented a little module the hooks ProcessPageView::execute(). I reviewed its code and found out, that the actual logic to look-up the requested page from the request is placed in a protected method ProcessPageView::getPage(). And because this method is currently not hookable, I needed to do a dirty hack (overriding the GET.it parameter that is inspected by ProcessPageView::getPage()). I suggest making ProcessPageView::getPage() hookable and pass the arguments for the page look-up via method arguments instead of inspecting the GET scope within the method.
  25. Hi fellows I have a problem with one of my hooks in processwire 3. It's a hook which manipulates the processpagelist to only show the pages which are not editable and not addable. This works fine in 2.7.3 but in pw 3 it doesn't work 100%. When the first time the ProcessPageList is rendered the hook works. Now when I open a branch and reload then it shows all pages. but when i close the branch before reload it works again and only shows the pages which are editable or addable. How it should look like: How it looks when i let the branch open and reload: PHP-Code $this->addHookAfter('ProcessPageList::execute', $this, 'hidePages'); public function hidePages(HookEvent $event){ $excludePages = new PageArray(); $the_pages = wire('pages')->find("template=newsletter-clinic|sender_2016|sender_2016_collab|inside-news-folder|event-clinic"); foreach ($the_pages as $the_page) { if(!$the_page->editable() && !$the_page->addable()) { $excludePages->add($the_page); } } $hidden = explode('|', $excludePages); if($this->config->ajax){ // manipulate the json returned and remove any pages found from array $json = json_decode($event->return, true); foreach($json['children'] as $key => $child){ if(in_array($child['id'],$hidden)) unset($json['children'][$key]); } $json['children'] = array_values($json['children']); $event->return = json_encode($json); } } Do you perhaps know what causes this and how to fix this?
×
×
  • Create New...