Jump to content

Martin Muzatko

  • Posts

  • Joined

  • Last visited

Everything posted by Martin Muzatko

  1. Is "custom_sort" a builtin of processwire? I wouldn't want to implement an extra field for that. Also: Since contentmodules can also be re-used on other pages, I don't know if setting the sorting on the page itself would help.
  2. I need to programmatically SET the order/sorting of the pages, not when getting the pages from the page selector field. The problem is, that setting the manual sort value of the page won't help, as they are neglected by the page reference field. To tell the full story: I'm building a CMS in a CMS. pageModules are set via Rest API: function setPageModules($page, $data, $contentPage = false) { $page->of(false); $pages = $page->pageModules; if (!$contentPage) { $contentPage = wire('pages')->get('template=page-contents'); } foreach ($data as $key => $moduleData) { if(isset($moduleData->id)) { $module = wire('pages')->get($moduleData->id); $module->of(false); setFieldValues($moduleData, $module); $module->save(); } else { $module = new Page(); $module->parent = $contentPage; $module->of(false); $module->template = $moduleData->template; $module->title = $page->title.'_'.$moduleData->template; $module->save(); $module->of(false); setFieldValues($moduleData, $module); $module->save(); $moduleData->id = $module->id; $page->pageModules->add($module); } } $page->save(); $page->of(false); foreach($data as $key => $moduleData) { // TODO: SORTING! // $module = wire('pages')->get($moduleData->id); // $module->sort = $key + 1; // $module->save(); } $page->pageModules->save(); foreach ($page->pageModules as $module) { $index = array_filter($data, function($item) use ($module) { return $item->id == $module->id; }); if (!count($index)) { $module->delete(true); } } $page->save(); } the $contentPage holds all content modules ever created. So it gets quite messy: So now I need to set the sorting, defined by the user input ( I get an array ob content module objects via my rest API) But there is no way to set the manual sorting of a page reference field. I will look through your thread horst. Thanks!
  3. Hello! I want to set the manual page sort of a page reference field with a pageArray. I found this existing thread which does not answer the question unfortunately. https://processwire.com/talk/topic/18510-sort-page-reference-field/?tab=comments#comment-162124 It looks like there are different concepts of sort. One that works with properties (sort=created) and one with a page as argument and index as second. However, I found this in wire\modules\Inputfield\InputfieldPage\InputfieldPage.module, that may explain how sorting is done when doing manual drag and drop. How can I reproduce that for my own sorting? // if pages were added, re-sort them in case they were dragged to a different order // an example of this would be when used with the InputfieldPageAutocomplete if(count($this->pagesAdded) && is_array($value)) { $sortedValue = $this->wire('pages')->newPageArray(); foreach($newValue as $page) { if($page->id < 1) $page = $this->pagesAdded->shift(); if($page->id && !$sortedValue->has($page)) $sortedValue->add($page); } $newValue = $sortedValue; $this->setAttribute('value', $newValue); }
  4. Hello! Can somebody else please take care of this? I'm deep in projects as of now. Otherwise, I will look into it later. Best, Martin
  5. See gif: When I use $sanitizer->pageName() to sanitize a title as name, I get a different result from what processwire automatically replaces, when editing the name in the CMS. I have to manually replace the dashes and even dots! I would expect the name to be equal to the last segment of the pagepath.
  6. It might be important to note, that while the path can be accessed via ->path, if the field is a multiple-image field. (Pageimages) Otherwise, for single items, it has to be ->pagefiles->path. At least this is what I have experienced. Not sure if I am doing something wrong
  7. I have the same problem. I can confirm it is not really a bug but unwanted behavior @ryan. It occurs, that when you delete pages and create ones (with the same name? in the same run, there is a problem with the correct page to be found. As the page still exists. Is there a way to delete a page not after the entire page call is done? I supposed there is some smart mechanism to make only one SQL query, instead of synchronously deleting pages. Thanks in advance. Right now, I have to resort to two page calls.
  8. If you haven't given #BEM a chance yet as #CSS architecture, I recommend this article https://t.co/BCR5ErmmFT by @sitepointdotcom :)

  9. I "fixed" it. I created a module that loads the pageTypes for me. <? public function init() { $this->addHookBefore('ProcessPageView::execute', $this, 'loadPageTypes'); } public function loadPageTypes($event) { require_once('site/templates/classes/PageTypes/Event.php'); } This makes the Page, when loaded by ProcessPageView, also available, and thus gets assigned the correct PageClass. Phew! I am not sure this is the best solution. Right now, it is all I have to fix it. Please let me know if there is a better way. What if I want to create a Composer/ProcessWire module with the pagetypes?
  10. I found the cause, but I don't know how to fix it. I think the Event.php Page class has to be loaded before PagesLoader checks for wireClassExists($template->pageClass). How should I go about that? If I package it as module, will it be loaded before the check? I am using Composer for my profile/theme and I autoload my pageTypes using psr-4. I guess the check comes before any _init.php is loaded. Somehow, there must be a possibility to hook into the render method to load the custom pagetypes before checking for wireClassExists in the PagesLoader.
  11. Hello! I started to implement this tutorial today. I am a little stuck with the advanced options. If I load a page, it is not of type Event, but if I get - for example - the next page, it is of type Event. It is always the loaded page, that is not of type Event, but of type Page. I think this is a bug in Processwire. To give you a better overview, this is what my events pages look like: Template, test-event and Another Event are all of template event. This is my Events PageType <?php namespace ProcessWire; class Events extends PagesType { public function __construct(ProcessWire $wire, $templates = array(), $parents = array()) { parent::__construct($wire, $templates, $parents); // Make sure we always include the event template and /events/ parent page $this->addTemplates("event"); $this->addParents($this->pages->get("/events/")); $this->setPageClass('Event'); } } As explained in the guide, I also set wire->events: <? // in _init.php $events = new Events($this->wire); $this->wire('events', $events, true); This is the Event page: <?php namespace ProcessWire; class Event extends Page { public function __construct(Template $tpl = null) { if(is_null($tpl)) { $this->template = $this->wire('templates')->get('event'); } if(!$this->parent_id) $this->set('parent_id', $this->wire->pages->get('/events/')->id); parent::__construct($tpl); } Both pages are included and the Event is set as the event templates system pageclass field: Now in the _init.php I debug the $events variable and try to access the methods in the Event class. <? \TD::dump($events->find('template=event')); foreach ($events->find('template=event') as $e) { \TD::dump($e->title); \TD::dump($e); } In the events homepage, this looks like this: So far so good! Now on a subpage, The opened eventpage, is all of a sudden of type Page! I also dump the page object in the event.php template. Do you have any ideas what I'm doing wrong? Thank you a lot in advance! Best, Martin
  12. Hello! When I create a custom pagetype by extending the Page class, as explained in the guides, all works good so far. However, if I want to get data of that page (like its children, etc) the data only seems to be initialized after calling a method. <?php namespace ProcessWire; class Event extends Page { public $registrations; public $items; public function __construct(Template $tpl = null) { parent::__construct($tpl); if(is_null($tpl)) { $this->template = $this->wire('templates')->get('event'); } if(!$this->parent_id) $this->set('parent_id', $this->wire->pages->get('/events/')); // is null? $this->registrations = $this->get('template=event-registrations'); } public function register() { $this->get('template=event-registrations'); // is different from $this->registrations } } So in __construct, there is no access to the page objects data, like title etc. But when I call a function such as $event->register, I get the proper data. So my question is, is there a way to initialize that data, without retrieving all the data only after I call the method? Or do I need to hook all methods and then do the data initializing? I think alternatively I could create a getRegistrations() function and call that in every other method where I need the registrations. Any ideas? Thank you in advance!
  13. Hi there @bernhard. This totally makes sense I didn't think about that I can already use the $user-> methods in this context. Awesome! I got tracy debugger installed, I just have to bring myself to use it more often Thank you a lot for the help, it is very much appreciated.
  14. @duckduckgo Do you have any plans to make the new bang suggestion process transparent? I can't even see if someone has already suggested it.

  15. Dear #javascript. Today I found out, that instead of blaming the back-end, I need to pass the credentials option for fetch to send cookies.

  16. Sure! no problem. I'll look into it Thank you a lot for the positive feedback.
  17. Weird! My image field is set to always return only a single item or none. I still get Pageimages in some cases, Pageimage in other cases. Weird is that I am always trying to get the image of the same object.
  18. Hello! I started to extend my user using a new class. All works fine, I am a little unfamiliar with the $event system, (Why can't we just have usual return values? This would make exiting a function at the right time a lot easier. Also plain function arguments would let me allow to better understand how to pass the $event to other functions) but it works. Now I want to re-use existing functions in other functions of the same class and it just does not work. The other functions in the same class are not callable and have - you guessed it - no return values. public function init() { $this->addHook('User::getMessages', $this, 'getMessages'); $this->addHook('User::getMessagesBySender', $this, 'getMessagesBySender'); } public function getMessages($event) { $user = $event->object; $event->return = $this->pages->find('template=message, receiver='.$user); } public function getMessagesBySender($event) { $user = $event->object; $sender = $event->arguments[0]; $event->return = $this->getMessages($event)->find('sender='.$sender); } What can I do to get the return values of other hooked methods? If I var_dump($this->getMessages($event)); I get NULL. How should I go about this? Are there maybe better methods of extending the user class in 2017? As you can see, getMessages is both a function I want to re-use, but also a hooked function. Thank you in advance!
  19. Hello there! I'd love to see more array operation functions such as map/reduce. There are already a few helpful functions there like pop, shift, etc. I find myself turning pageArrays into arrays, do array_map or similar and create pageArrays again from that data. For Processwire, it would be really helpful to perform forEach operations more comfortably. E.g. <?php $allTitles = $pages->map(function($page){return $page->title}); // vs traditionally: $allTitles = []; foreach($pages as $page) { array_push($allTitles, $page->title); } $pages->reduce would be really helpful too. This would avoid many in-between variables when calculating sums of fields stored in individual pages. Thank you in advance Best, Martin
  20. Hey there! I'm using the latest Processwire (3.0.62) I think I fixed it. I disabled Link Abstraction, this fixed it for me. Thank you anyway!
  21. Hi there! I have another processwire instance on the same server. However, when I place a link to that sub-instance, processwire overwrites the link. The original link was http://happy-css.com/api/users/?name=jo but it gets overwritten with http://happy-css.com/processwire/access/users/?name=jo Is there any setting I can change to forbid processwire to change that link? Especially when it is an absolute link I set, not a pagelink. Best, Martin
  22. Hello. Thanks for your reply. I know that sessions are supposed to work like that. I only wonder why the $user variable is only populated after a complete refresh. After all, after a successfull $session->login, I would expect $user->isLoggedIn() to return true. Even without a page refresh. I wanted to display a little welcome message, or logout message, but I think I can also achieve this by redirecting him to another page. This is my current code - with the redirect in place. <?php namespace ProcessWire; if (count($input->post()->getArray())) { $loginUser = $session->login($input->post->username, $input->post->password); if($loginUser instanceof User) { $session->redirect($pages->get('/')->url.'users/'.$loginUser->name); } } if($user->isLoggedin()) { $session->redirect($pages->get('/')->url.'users/'.$user->name); } ?> <form action="" method="POST"> <input type="text" name="username" autocomplete autofocus value="<?=$input->post->username?>"> <input type="password" name="password" autocomplete value=""> <input type="submit" value="Login"> </form>
  23. Hello there! I want to create a user front-end (user can register/login/logout via templates) I'm working based on the intermediate site profile. So _init.php is loaded first, then the template file and then _main.php. I integrated the custom login as described here, and changed it to my needs. ( I don't want to redirect the user, if the form is filled in successfully) The problem I face, is that $user->isLoggedin() lags behind $session->login(). Which means that whenever I do a login, I DO get the information that the login was successful ($session->login(...) instanceof User). I COULD use that information on _main.php to show a profile in the upper right corner. However I don't want to set a variable in the template and ask for it in _main.php. Are there any alternatives? Is a redirect really required to complete the session handling? Why? I have the same problem for the logout. The user is still displayed as logged in, when he opens the logout page. Thanks in advance. Best, Martin
  24. For future people having the same question: https://github.com/ryancramerdesign/SkyscrapersProfile/blob/master/site/templates/includes/functions.php#L47-L56
  25. @matjazp I'm not sure. I made it now work with the following: $data = new WireInputData([ 'email' => $input->post->email, 'username' => $input->post->username, 'species' => $input->post->species, 'firstname' => $input->post->firstname, 'lastname' => $input->post->lastname, 'password' => $input->post->password, 'password_repeat' => $input->post->password_repeat, 'email' => $input->post->email, 'street' => $input->post->street, 'zip' => $input->post->zip, 'city' => $input->post->city, 'country' => $input->post->country, 'birthday' => $input->post->birthday ]); $token = $session->CSRF->getTokenName(); $data->$token = $session->CSRF->getTokenValue(); $post = $input->post; $post->setArray(array_merge($data->getArray(), $post->getArray()));
  • Create New...