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! The only hook into 'trash' in a module runs twice, by itself, as it seems. The following code outputs: Session: Hooked 1 times on abcd Session: Hooked 2 times on abcd on the admin side when one page is deleted from it's delete tab. And it's no matter 'addHookBefore', 'addHookaAfter' or 'addHook' method is used. Why?! private $i = 0; public function init() { $this->pages->addHookBefore('trash', $this, 'test'); } public function test($event) { $page = $event->arguments('page'); $this->i++; $this->message("Hooked {$this->i} times on {$page->title}"); }
  2. Hi there! I'm using ProcessWire 3 and I'd like to build a module that tabs into the ProcessPageView::execute hook. Currently I've built a small module that defines the hooking in its init() method as usual. public static function getModuleInfo() { return [ 'title' => 'MicrositeRouting', 'version' => 001, 'summary' => 'Routing logic for microsites', 'requires' => 'ProcessWire>=3.0.14', 'autoload' => 'template!=admin', 'singular' => true ]; } public function init() { $this->wire('log')->message(__METHOD__); $this->addHookBefore('ProcessPageView::execute', $this, 'lookUpPage'); } public function lookUpPage(HookEvent $event) { $this->wire('log')->message(__METHOD__); } I provided some log messages to check if the module works. But it seems that in spite of the module being initialized properly (the message is found in my logs), the hook itself isn't processed at all (the log doesn't show the corresponding message). I surely missed something important but currently can't find it. Thank you for any suggestions.
  3. hi, is it possible to change field parent_id from InputfieldPageListSelect to InputfieldPageAutocomplet by addHookAfter('ProcessPageEdit::buildFormContent')? thanks, martin
  4. Hello community, we have a website running version 3.0.118. The owner would like to have a watermark merged to the images, that are being uploaded in the CKEditor as a requirement. Image upload besides the CKEditor within galleries and single images works as a charm already. We also use croppable image 3 there. (PIM2) To realize this requirement, I thought of using a hook in the admin area. So, I read a lot in our forums and tested this by adding a hook into the ready.php file. $this->addHookAfter('InputfieldFile::fileAdded',function(HookEvent$event){ wire('log')->save('test','Image upload works'); ... The log entry is being created correctly. But when I try to use the pim/watermark-function like in a template, he cannot find the watermark-image anymore. Furthermore, when I try to get the page-id, it does not seem to be accessible, because the application does not seem to know how to reference it, or I dont know the right way to do so… So my questions are: Is this the right attempt at all or will there be another, better workaround? It seems, I cannot access the page object (of the content page) within this scope or file but I would need it to save the processed image inside the right files/id folder Would it be better to place the hook into the admin-template? (or admin.php) Thanks for any hints in advance. ?
  5. ? PW Pros… I have some hooks that I need to bind at the init phase (or even __construct) and I was wondering, and I couldn't find a good and simple way to determine if I'm in the admin. Would be nice if there is a reliable short option to do so, but I can't seem to find one… Is there a coherent way to tell this no matter where I am? Right now, I use the following method inside one of my modules: public function isAdmin($page = null) { if ( strpos($this->input->url, $this->urls->admin) !== false || $this->process instanceof ProcessPageList || $this->process instanceof ProcessPageEdit || ($page instanceof Page && $page->rootParent->id == $this->config->adminRootPageID) ) { return true; } return false; } @ryan wouldn't it be nice to have something like wire()->isAdmin(); like wire()->user->isLoggedin(); to tell if we are in admin – very early on (probably even in __construct() phase of modules?
  6. 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!
  7. 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!
  8. 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.
  9. 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?
  10. I got a field with a type of "files" named: course_file .. how can I upload it to custom directory??
  11. 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
  12. $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.
  13. 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.
  14. 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
  15. 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?
  16. I want to remove "Breadcrumbs" From Some Admin Pages .. for example (Modules/Profile) Pages. Aslo: How To Modify Page Headline .. Thanks .
  17. 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
  18. 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
  19. 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.
  20. 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?
  21. 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.
  22. 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?
  23. 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.
  24. 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.
  25. 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
×
×
  • Create New...