torf
Members-
Posts
78 -
Joined
-
Last visited
Everything posted by torf
-
Wow. Cool one. It absolutely works. I cannot use it in my special case as I have to use ready.php (the field is used in two templates and only one uses the parent as selector. So I need to use an if statement to determine the actual template), but it's good to know it works that way as well.
-
Thanks a lot. In that case I just use the normal select. Changing core files only leads to trouble and I try to avoid it if not absolutely necessary.
-
I have a page reference field that only shows certain pages based on a field on the the chosen page that also exists at the parent page. To get the allowed pages I added in ready.php $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if ($event->object->hasField == "my_page_reference_field") { $page = $event->arguments(0); $zv = $page->parent->name; $event->return = $event->pages->find("template=myTeplate, searchterm=$zv"); } }); As long as I use radiobuttons or select field this works great. But using automplete I get all the pages from the whole site. Does anybody know why this happens?
-
Thanks a lot. My mistake was to look for the title. That does not work directly. So with your help I managed to get the data I needed. $searchterm = $input->urlSegment1; $myPage = $pages->findOne("template=Template1, title={$searchterm}"); $myList = $pages->find("template=Template2, PRfield={$myPage}"); That works as expected.
-
I'd need some advice how to search for specific pages that have use a certain value in a page reference field. The task is quite simple: find all pages with a certain template that also use a page reference field with a specific title. $pageList = $pages->find("template=myTemplate, {PRField->title}={$input->urlSegment1}"); I also tried to split it but to no avail: $pageList = $pages->find("template=myTemplate, {PRField->title}={$input->urlSegment1}"); $finalpageList = $pages->find("{$pageList->PRField->title}={$input->urlSegment1}"); I'm absolutely positive that I'm missing a crucial point here.
-
@flydev Wow. Thanks a lot. That absolutely does work and I'm positive that I'd never figured that out on myself. Thanks again. @Robin S That's a cool approach too. Especially as it is very short. But I'm unsure about the CSS parts. Am I right that those CSS files need to be called directly inside admin.php rather than from site/ready.php ?
-
I do not think that this would help. It's not so much about handling the pagination. I'd need to turn it off for certain roles. I added two Screenshots to the original post to make it more clear. There are 127 pages under "Zweigvereine", but the user is only allowed to see the one he's able to edit. So he has 2 empty pages before his link appears on the third one. If I could turn of pagination for his role his page would be listed directly.
-
I have a long list of pages in my backend that uses pagination to be less confusing for my editors. Works great. Now I have another role, where every user with a specific role can edit only his own page out of this list. Thanks to Page Edit Per User and Admin Restrict Branch that works great as well. Additionally I added a small part to my ready.php to hide all the other pages this user cannot edit: if($this->user->hasRole('specificRole')){ $ap = $user->editable_pages[0]->id; //there is always only one page $wire->addHookAfter('Page(id!='.$ap.'|1058)::listable', function($event) { //1058 is the id of the parent page $event->return = false; }); } But my problem is that the pagination still works. So a user with editing rights on a page named "zzzzz" for instance has to klick on the last page of a set of empty pages to see his link. Is there any way I can turn of pagination just for this specific role?
-
@Zeka I wholeheartedly agree to most of what you wrote. The first version is more beautiful and presumably more performant. But as in most cases this is a small clients projects. Meaning nobody is ever going to look at that code and judge it by those standards. As soon as the page is online no one (including myself) will look at the code for a long period of time. Then my client will ask for some changes and I - or even worse - a new person will open that site and try to figure out how things are happening. And at this point the first version has its flaws. From the viewpoint of structure the second version (although not as beautiful) is better to handle. I have everything regarding one workflow at one point. So anyone not familiar with the code can look for "what happens with field1?" without gathering together bits and pieces shattered over half the document. Of course i can use comments but it's still like "what you are looking for is in shelf 1" vs. "What you are looking for is in shelf 1, 2, 5, 12 and some minor places I surely forgot to mention". So if performance issues are neglectable I'd rather prefer the second version for any page that is not maintained on a regular basis.
-
I was wondering: when I use the same hooks on different pages, is it better to only use that hook once and divide with if statements or is it ok to call a hook multiple times. Like: $wire->addHookBefore('Pages::saveReady', function(HookEvent $event){ $page = $event->arguments(0); if($page->hasField("field1")) { //do something } if($page->hasField("field2")) { //do something else } }); $wire->addHookAfter('Pages::unpublishReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->hasField("field1")) { //do something } if($page->hasField("field2")) { //do something else } }); or //Things regarding pages with Field 1 //###################### $wire->addHookBefore('Pages::saveReady', function(HookEvent $event){ $page = $event->arguments(0); if($page->hasField("field1")) { //do something } }); $wire->addHookAfter('Pages::unpublishReady', function(HookEvent $event) { if($page->hasField("field1")) { //do something else } }); //###################### //Things regarding pages with Field 2 //###################### $wire->addHookBefore('Pages::saveReady', function(HookEvent $event){ $page = $event->arguments(0); if($page->hasField("field2")) { //do something else } }); $wire->addHookAfter('Pages::unpublishReady', function(HookEvent $event) { if($page->hasField("field2")) { //do something else } }); //###################### Of course the first version looks nicer, but if you have a lot of functions it becomes increasingly confusing to keep track of those functions. The second version makes it much easier to keep logic together but I'm concerned if that will raise trouble with performance.
-
@BitPoet Oh. I missed that little piece of Information. Thanks a lot. And you're right. I'll have a look into Pages::publishReady. @bernhard and @Jan Romero I admit that it would be nicer without an extra field, but as there is the possibility that the date needs to be changed manually in the future I'd rather go with an additional field before I have to reinvent everything in five months.
-
I need to show (in my backend) since when a page special type of page has been published (not created, as there may be a long delay between creation and publishing). So I made a datefield in my template and added following code to my site\ready.php $wire->addHookBefore('Page(template=templateName)::published', function($event){ $page = $event->arguments(0); $this->message("the Hook has been called"); if($page->hasField("myDateField")) { $newDate = date("d.m.Y"); $page->myDateField = $newDate; } }); But for some reason the hook is not called when I publish the page. Is there something I'm missing?
-
My task is to give users edit permission to their specific page (not created by them) as long as the page is unpublished and somehow I can't get it to work. The idea would be user can only access a special branch in the backend (I do not want them to see all the pages) in this branch there are dozens of pages (same template) but each user can only access his personal page as long as the page is unpublished they can edit and save it the publishing permission is with another role as soon as the page is published the user may see it in the backend, but has no more editing permission So the idea was to use Admin Restrict Branch and Page Edit Per User modules which both work great. But Page Edit Per User seems to fiddle with the permissions, so the user can still edit his published page even if he has no page-publish permission. Is there any way I can revoke the page edit permission manually after the page is published (and reinstall it when the page is unpublished again)?
-
Works like a charm. Thank you very much.
-
That's a very handy module. Thanks a lot. Where I got a bit into trouble is adding multiple classes to a table, as it keeps replacing every space with an "-" and makes it therefore impossible to add multiple classes (like for instance "table table-striped" gets saved as "table-table-striped". I suppose that's the sanitizer function. Have you got any idea for a workaround?
-
I already thought of purchasing Profields, but as far as I understood profields-table creates a specific DB-Table for every table. That would create about 20-50 tables in my database, each for just a couple of data rows. Thats the sort of overhead I'm trying to avoid.
-
I have a couple of pages - all with the same template - and each page needs a couple of small tables for additional data. All of them with totally different rows and columns. I looked into Matrix Fileds, which is a wonderful Module, but as I need about 10 or more different tables that would need dozens of pages to set up rows an columns. Same goes for repeater fields, as I'd need a repeater for every kind of table. Of course the easiest way would be to set up those tables in CKeditor, and just display them, but the table interface in CKeditor is quite messy and I fear the later editors of the site will mess them up in no time. Can anyone think of an easy way to set up tabular data which is displayed as tabular data in the backend, without preparing dozens of fields or pages?
-
Thanks @teppo!! Sometimes taking a second look helps. The Domain "view" is pointing to has a "www", while the backend I used has not. Now I know where I need to make adjustments.
-
I have a strange issue when previewing unpublished pages, and need some advice how processwire is supposed to work: When I add a new page in my tree a logged in user can preview the page even when it is unpublished via the view button. On my production site this is no problem and would of course be the desired behaviour. But on my live site clicking on "view" ends in a 404 every time as long as the page is unpublished. That even happens when I'm logged in as superuser. What is the "normal" behaviour" and does anyone know what could cause that effect?
-
server running out of memory when embedding multiple images in CKEditor
torf replied to torf's topic in General Support
If anyone stumbles over that again - deleting $this->message($event); did the trick. Now it works. -
server running out of memory when embedding multiple images in CKEditor
torf replied to torf's topic in General Support
Sorry, I've been offline shortly. Mostly the Error occurs in wire/core/sanitizer.php on line 2555: public function entities($str, $flags = ENT_QUOTES, $encoding = 'UTF-8', $doubleEncode = true) { if(!is_string($str)) $str = $this->string($str); return htmlentities($str, $flags, $encoding, $doubleEncode); //<-- Thats line 2555 } sometimes in wire/core/Notices.php Line 523 protected function formatNotice(Notice $item) { $text = $item->text; if(is_array($text)) { $item->text = "<pre>" . trim(print_r($this->sanitizeArray($text), true)) . "</pre>"; $item->flags = $item->flags | Notice::allowMarkup; } else if(is_object($text) && $text instanceof Wire) { $item->text = "<pre>" . $this->wire()->sanitizer->entities(print_r($text, true)) . "</pre>"; //<-- Line 523 $item->flags = $item->flags | Notice::allowMarkup; } else if(is_object($text)) { $item->text = (string) $text; } if($item->hasFlag('allowMarkdown')) { $item->text = $this->wire()->sanitizer->entitiesMarkdown($text, array('allowBrackets' => true)); $item->addFlag('allowMarkup'); $item->removeFlag('allowMarkdown'); } } -
I stumble upon a strange problem regarding images in rich text fields. For a section I use CKEditor for the Content. Additionally there is a imagefield for each page where inline images for this article can be uploaded. then the editor can take those images and embed them in CKEditor. In the Frontend the images are shown inline with a additional lightbox which is preformatted via ready.php: $wire->addHookAfter('TextformatterProcessImages::processImg', function(HookEvent $event) { $this->message($event); $pageimage = $event->arguments(1); $img = $event->arguments(0); if($pageimage) { $img->outertext = "<figure class='figure'><a data-fancybox='gallery' data-caption='{$pageimage->description}' class='lightboxclass' href='{$pageimage->url}'><img src='{$pageimage->size(600,0)->url}' class='figure-img img-fluid rounded' alt='{$pageimage->description}'/></a><figcaption class='figure-caption text-end'>{$pageimage->description}</figcaption></figure>"; } }); There is no Problem embedding and saving those images, but the moment a new article is published, and it has more than one image inline, the frontend gives me an "out of memory" php-error. PHP memory is set to 512MB which I think should be enough. Has anybody an idea if there is a problem that creates a loop in my script, or is it just not enough memory? Thanks for any help. PS: the problem occurs regardless of image size. If I take 12KB images or 12MB. It's always the same.
-
Thanks, but what permission is it? If I knew I could just give this permission to my userrole, but only superuser seems to get the "choose parent" page. And I cannot give superuser rights to my users.
-
I have a strange behaviour that I cannot fully understand. In my page there are child pages who themselves have subpages. Home Child 1 Child 2 Sub 2.1 Child 3 Sub 3.1 Sub 3.2 A couple of my roles have the right to add new subpages to any of the childpages. Works great if I use the treen navigation and "new" beside one Child. But if I use the "add new" button on the right, or the "add new" link from dropdown in the header, only the superuser is shown a page to choose the parent before adding the subpage. For any other user it directly creates a subpage in one of the children. Does anyone know which right is needed to get the selector for other roles than superuser?
-
Thanks for this wonderful and extremely helpful module, but I was wondering if there is a possibility to assign more than one role to a user with this module? I have 4 roles with basically the same rights but access to different branches of my site (access is granted by role). Now if I give a user more than one of this roles Admin Restrict Branch gives them access to only the first branch but not the other ones. I'm aware that it is not possible to have multiple branches in one role, but is it somehow possible to mix branches with multiple roles for one user?