Jump to content

---

Members
  • Posts

    23
  • Joined

  • Last visited

Everything posted by ---

  1. I've got this code to fetch all pages: /** @var PageArray $pages */ $pages = $this ->wire('pages') ->find(sprintf( 'has_parent!=2,id!=2|7,status<%s', Page::statusTrash )); With this I fetch all pages except admin, but that includes the 404 page as well. Is there a way to exclude pages like the 404 page from the result? Or maybe loop through the result set to check for the pages response code (without curl that is)? I want to avoid filtering the 404 page by ID if possible.
  2. By any chance, do you know how to set a width on the table columns?
  3. Ah ,that's quite simple actually. It's working now, thanks!
  4. I'm using this piece of code to add a table layout to my module configuration: $this ->wire('modules') ->get('MarkupAdminDataTable') Then I use this to add rows to my table: $this ->wire('modules') ->get('MarkupAdminDataTable') ->row($data) But when I try to add a field to my table, It's not rendered as a field, I only see the the classname of the input field instead of the field itself. Is it possible to render a field into a table row?
  5. In my module's getModuleConfigInputfields method, I've added a field of type: InputfieldButton. I want this button have a different action than the usual submit button (which is still there) and the submit button to behave as it always does. For example; I want the InputfieldButton button to clear a few folders when it's clicked. Is this possible, if so, how can I achieve this?
  6. I use it in a before hook method page::render with prio 1.
  7. Sorry, forgot to mention; I want to do this inside a module method. When I do `$this->page->rootParent->id`, it will give me the following error: <b>Notice</b>: Trying to get property of non-object in So I've tried $this->wire('page') instead, but that method returns null.
  8. How can I check if the user is in the admin enviroment of processwire? At the moment I'm using some buggy url check but I figure that there must be something in processwire itself to check for that. I don't want to check if the user has administrator privileges, just if the user is visiting an admin url. Because the admin url can be changed from the admin panel I don't want to check on something hard coded as well. What is the best way to check for an admin page?
  9. 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?
  10. I've written a hook which replaces the page::render method. Based on a few conditions, I might want to output something different from what page::render would return. So when my conditions aren't met, I want to use the return value of the original page::render method. How can I do this? At the moment I've got something like this: function pageRenderHookMethod (HookEvent $event) { if ('my condition' == true) { $event->replace = true; $event->return = 'my custom return value'; } else { $event->return = 'original return value of page::render'; } } But I don't know how to get the original return value of page::render because the would trigger my hooked method instead of the original method.
  11. 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.
  12. Well it's in my first post: What I want, is that my menu, footer etc. are still visible but only the content of that page is replaced. I want to have a hook method in which I alter the content of the body based on a few conditions, but I don't want to replace the full HTML, only the content of the page, so that my menu, footer etc are still visible.
  13. I still think it's more ugly than using a hook because if you get more of these exceptions to add to this file it becomes fat and less readable about what it does. I found out that I just need to get a hook on \ProcessWire\TemplateFile::setFilename, but unfortunately that isn't a hookable method:/
  14. That looks like an uggly hack since that could be any page? Wouldn't it be way better to perform such logic in a module instead of a template file?
  15. Okay, and then? Because so far I only managed to get the full html page while I just want to reaplce $page->body (as an example). Yes, I know that, but that is in a template file. I want to alter it without using a template file as it should only be altered under specified conditions.
  16. I have a hook to change the template file on a certain page. This is not working at the moment for some reason. The usual location to place templates is under /site/template. Because the template should only be available in my module, I want my template file to be in /site/modules/mymodule/view/mytemplate.php When I place my file in the usual template location, it works fine. But when I place the file in my module folder, it doesn't work. When I var_dump the $page->template->filename variable, the location of the template file is correct and maps to my module folder. So everything seems to be correct, but somehow it's not working but I can't figure out the problem. Does anyone know how to solve this?
  17. How can I change the output of `Page::render`? I've created a hook before page::render, but when I set the $event->return to something else, my whole page is replaced with that value. For example: public function beforePageRender(HookEvent $event) { $event->return = 'blaat'; } This will cause my whole page to be nothing more than just 'blaat'. What I want, is that my menu, footer etc. are still visible but only the content of that page is replaced.
  18. I'm trying to create tests using PHPUnit, and I have the following method: protected function _getRootItems(Page $currentPage) { /** @var Page $page */ foreach (wire('pages')->find("has_parent!=2,id!=2|7,status<" . Page::statusTrash . ",include=all") as $page) { if ($this->_isActivePage($page) && $page->parent_id == 1) { $output[$page->sort] = [ 'id' => $page->id, 'title' => $page->title, 'url' => $page->url, 'template' => $page->template->name, 'isActive' => $page->id == $currentPage->rootParent->id, 'children' => [] ]; } } ksort($output); return $output; } I want to write a test for this method in PHPUnit. I end up with the error: Trying to get property of non-object This is because $currentPage->rootParent is null. My test looks like this: public function testGetRootItems() { $mock = $this ->__getMock() ->disableOriginalConstructor() ->setMethods([ '_isActive' ]) ->getMock(); $mock ->expects($this->any()) ->method('_isActive') ->willReturn(false); $page = $this ->getMockBuilder(\ProcessWire\Page::class) ->disableOriginalConstructor() ->setMethods([ '__get' ]) ->getMock(); $rootParent = $this ->getMockBuilder(\ProcessWire\Page::class) ->disableOriginalConstructor() ->setMethods([ '__get' ]) ->getMock(); $template = $this ->getMockBuilder(\ProcessWire\Template::class) ->disableOriginalConstructor() ->setMethods([ '__get' ]) ->getMock(); $template->name = 'name of the template'; $rootParent->id = 1; $page->template = $template; $page->id = 2; $page->rootParent = 'hierzo!'; var_dump( $page->rootParent ); $method = $this->__getReflectionMethod('_getRootItems', $mock); $method->invoke( $mock, $page ); } I've already tried to override the rootParent with it's method (___rootParent), tried setting it directly ($page->rootParent) but so far nothing worked. I probably miss something really simple here. I know that in my example, I set the value to a string. But the result of the var_dump below it is still NULL. I also tried setting it using $page->rootParent = $rootParent, this had no effect. So my question: How can I possible override this rootParent variable?
  19. I'm using PHPdocumentor to generate documentation of my modules, but it fails to scan the .module files. Is there another way of making processwire see a module other than giving it a .module extension? I'd like to rename my module file to .php but then processwire no longer sees my module.
  20. Hi, I have a method (___renderImage) which renders an image tag (<img src) and has a single argument: Pageimage $image. Now I have a hook called "beforeRenderImage" in which I'd like to add a property to the argument of ___renderImage. So for example, I'd like to add a property "requiredDimension" to the argument before ___renderImage is called. Is this possible?
  21. Oh wow... Never knew there were filters in the backend.Thanks! Makes my life a whole lot easier!
  22. Well I can't add a field to the languages config page as far as I know. I want the field to be visible when editing a language page in the admin section: Screenshot When I edit "default", "de" etc, that's where I want an additional field and the only way I could find that was working and didn't require editing core files was using a hook. If you know a better way to add a field on that place, please let me know.
  23. I've added a hook after the '"ProcessPageEdit::buildFormContent" event. I've added a new config option to the language settings: public function beforeAdminProcessPageEditBuildFormContent (HookEvent $event) { $editPage = $this->getPage(wire('input')->get('id')); if ($editPage->template->name == 'language') { // only add field when editing language page $field = wire('modules')->get('InputfieldText'); $field->attr('name+id', 'locale'); $field->label = __('Locale'); $event->return->insertAfter($field, $event->return->getChildByName('title')); } } I've also created a field (Setup > Fields > Add new) which I've also named 'locale'. The field is displayed, but the value isn't saved when I click the save button. How do I make sure the input of the field is saved as well? And how can I access the stored value once it's saved?
×
×
  • Create New...