-
Posts
4,928 -
Joined
-
Days Won
321
Everything posted by Robin S
-
Does $p->children()->eq() first return all child pages?
Robin S replied to Matte85's topic in API & Templates
In the selector that you use with the children() method, you can do anything that you can do in a $pages->find() selector. Because behind the scenes... $page->children($selector) ...is essentially... $pages->find("parent=$page, $selector") Like I said, I'm no expert on multi-language, but I think PW has tools that let you handle multi-language smarter than this. Have a read here about multi-language fields and here about language support in general. -
You are right. It seems that when the hook fires for the AJAX reload the process is ProcessPageView and not ProcessPageEdit. So @Juergen's way of getting the page from the id GET variable would be the way to go.
-
getPage() is a method of ProcessPageEdit. It's fine to use it, but you first need to check that the current process is ProcessPageEdit. if($this->process != 'ProcessPageEdit') return; $page = $this->process->getPage(); // ...
-
@Macrura, would you mind testing the attached module update and let me know if it works as expected and improves the page load time? Just want to confirm it does the job before pushing the change to GitHub. CustomInputfieldDependencies.zip
-
Hi @Macrura, looking at the module code I can immediately see a much more efficient way to match the current page than what the module is doing currently. I'll post back here shortly with an update.
-
Does $p->children()->eq() first return all child pages?
Robin S replied to Matte85's topic in API & Templates
Could you explain more about this? I haven't built multi-language sites myself, but I'm not seeing how translations would have an affect on applying the limit within the selector as opposed to getting individual children with $parent->children()->eq($i). If your limit is 5, but there are only 3 children under a particular parent, then of course you will only get 3 children returned. But that is the same with eq() also. Note that if you want to return only pages with some particular template, property, field value, etc then you can specify that in the selector for children(), e.g. // Return children up to $limit where my_field is not empty $items = $parent->children("my_field!='', limit=$limit"); -
Module: Video embed for YouTube/Vimeo (TextformatterVideoEmbed)
Robin S replied to ryan's topic in Modules/Plugins
The strange thing is though is that you have working embedded YouTube videos on that site here: http://www.burstoncrown.com/events/easy-thursdays/jess-morgan-and-kitty-macfarlane/ Perhaps the host is running mod_security or similar and that is being triggered by particular patterns in some video URLs? -
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
@oma, when you use a date/time as a string in a $pages->find() selector it is internally passed through strtotime(). So if you are doing a separate strtotime() elsewhere that you want to give the same result you must use the same string, i.e. use "today" for both or "now" for both. -
@ryan, this part of the blog post... ...seems to contradict the setting in /wire/config.php, where... $config->defaultAdminTheme = 'AdminThemeDefault'; Shouldn't the default admin theme used for new installations match that defined in /wire/config.php? Also, is it possible to define a setting specifying the previous AdminThemeDefault as the default theme for new installs? Speaking for myself, I'm not ready to shift to AdminThemeUikit just yet and it's likely that aspects of my custom profile that I choose on installation are not compatible with AdminThemeUikit.
-
Does $p->children()->eq() first return all child pages?
Robin S replied to Matte85's topic in API & Templates
It does return all children if you use the children() method without a selector, or use children as a property. You could do that more efficiently as: foreach($parent->children("limit=$limit") as $child) { //... } -
It's working for me. Double-check the hook code, or maybe you have some other module or hook interfering? AdminTheme::getExtraMarkup should never return null - even if it's unused it still returns an array. $wire->addHookAfter('AdminTheme::getExtraMarkup', function(HookEvent $event) { $parts = $event->return; $parts['head'] .= '<link rel="stylesheet" href="/site/templates/custom.css">'; $event->return = $parts; });
-
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
I misunderstood - I thought you wanted to sort by the most distant upcoming date, not the soonest upcoming date. So you'll need a different approach I think, where you loop over your result pages add them to a new array using the next upcoming date as the key, then you sort the array by key. Edit: after thinking some more, this is not an ideal solution because your upcoming date timestamps may not be unique, so they don't make good candidates to use as array keys. A better idea is to add the next upcoming date timestamp as a custom property of each result. So the general principles... 1. Keep the "events_detail_dates_sort_date" field in your template, but instead of populating it with the soonest upcoming date you populate with the most distant upcoming date in the saveReady hook. This field will not be used to sort the pages (so you could consider renaming it if you like) but rather to exclude pages that have no upcoming date in your $pages->find() selector, so that you are not having to process more pages than necessary. 2. Loop over the raw unsorted results of your $pages->find() query, adding the timestamp of the next upcoming date as a custom property. Then sort on that property: // For each of your $pages->find() results... foreach($results as $result) { // Test for the template of the result here // ... // Get the repeater page with the next upcoming date $next_upcoming = $result->events_detail_dates->get("events_detail_dates_start_date>=$today, sort=events_detail_dates_start_date"); // Add the timestamp of the next upcoming date to the result as a custom property $result->next_upcoming = $next_upcoming->getUnformatted('events_detail_dates_start_date'); } // Sort the results by the custom property $results->sort('next_upcoming'); // Now loop over $results to output the markup You'll need to expand on this to deal with the other template ("Our pick") you are including in your results. So you would first test for the template of the result page and use the above if it is "events-detail" and come up with some other numerical value for the "our pick" results to use as "next_upcoming" so they appear where you want them when sorted by the custom property. -
The UIkit theme is looking lovely, but does anyone else think it goes a little too far in terms of padding? On my 27" monitor this interface looks quite large. On something like a 13" laptop you would not get much interface on the screen it would require a lot of scrolling. I love clean whitespace as much as the next person, but there is more than just aesthetics to consider. The admin interface is something that as developers we are going to spend a significant amount of time using. The extra scrolling and mouse movement that a widely-spaced interface requires is something to consider. Definitely not wanting a cramped, crowded interface but I think there is scope to be more efficient here, particularly in the vertical padding. In designing a utilitarian interface like this I would be inclined to follow a process of starting with no padding and then adding padding to elements by eye until it feels right.
-
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
Oh right, that's because you can't use spaces around field/operator/value in selector strings. I was just composing that in the browser. If you change to... if($article->template->name == 'events-detail') { if(count($article->events_detail_dates->find("events_detail_dates_start_date>=$today"))) include './inc/events-item.inc'; } //... ...it should work. Not sure why it would need to auto update apart from when the page is saved. It only needs to update if you are making a change to the page by adding or removing a date. In terms of old dates you exclude those in the $pages->find() selector that gets your results: events_detail_dates_sort_date>=$today -
If you are using Page Reference fields there is some limited support for this. See this post:
-
If you want to add a CSS file so that it is linked at the bottom of the list of admin styles and scripts you can use a hook like this: $wire->addHookAfter('AdminTheme::getExtraMarkup', function(HookEvent $event) { $parts = $event->return; $parts['head'] .= '<link rel="stylesheet" href="/path/to/custom.css">'; $event->return = $parts; });
-
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
Of course it depends on what you are iterating over, but in general foreach is very efficient. For instance, I've read that when working with a plain PHP array it is often more efficient to use foreach in place of dedicated PHP functions such as array_map and array_reduce (although for most situations that would be micro-optimisation and you would just use whichever is most convenient). I don't think that kind of sort would be possible in a selector, where you want to look through all repeater items and sort their containing pages by the most distant date. I think when you sort by a value contained within a multiple-page field (repeater, page reference, etc) the sort happens on whatever is the first page in that multiple-page field. So therefore you would need to apply some automatic sort to the repeater items so that the most distant date is always first, and that isn't so easy to do. If you have Profields Table then that has an option to automatically sort by a column. Or you might have to create a hidden field in the event template and populate it with a saveReady hook so it contains the most distant date, then sort by that field. To shorten your code you could do away with the nested foreach and do something like: if($article->template->name == 'events-detail') { if(count($article->events_detail_dates->find("events_detail_dates_start_date >= $today"))) include './inc/events-item.inc'; } //... BTW, where you are not mixing HTML and PHP you don't need PHP open/close tags on every line - you can just put the whole block of PHP code between a single pair of open/close tags. It doesn't do any harm the way you are doing it, but perhaps a little harder to read. -
each user allowed to add only one page under a parent template
Robin S replied to ziu's topic in General Support
Another approach is to not allow users to create pages at all, but rather automatically create a single unpublished page for each user in a hook at the time the user is created. Then each user can populate and publish their page if they wish. -
Using markup regions causes template to render twice?
Robin S replied to jtborger's topic in API & Templates
Check out Tracy Debugger and you'll be glad you did. Then rather than using var_dump and echo you can use the bd() function in your files to get a lovely expandable dump output and the "double output" thing won't be an issue with Markup Regions. -
@taoguang, I think you might be mixing up two different approaches to tagging. This looks like you have a text field with comma separated tags. But you don't need this if you are using pages for your tags - you can use a Page Reference field to add the tag pages directly. So like you quoted in your post:
-
@Tom., there does seem to be something funny going on in this case when hooking before Pages::save. Will do some more testing, but to allow you to move forward with your project the quick solution is just to hook after Pages::save. So in the test case: $wire->addHookAfter("Pages::save", function(HookEvent $event) { $page = $event->arguments('page'); if($page->template == 'bug' && !$page->skip_me) { for($i = 0; $i < 3; $i++) { $p = $page->repeater_2->getNew(); $p->text = 'Bug'; $p->save(); $page->repeater_2->add($p); $page->skip_me = true; // prevent recursion $page->save(); } } }); Edit: did some more testing using a Page Reference field and managed to trace it back to the "uncacheAll" option in PagesEditor::save(). Posted a comment on the other GitHub issue, which is definitely related to your issue. Hopefully Ryan can fix it soon.
-
I know, and I can't reproduce any problem, so more of a step by step guide to reproducing the issue on a clean PW installation would be helpful.
-
Is it possible to change the Notes of a field with a Hook?
Robin S replied to PWaddict's topic in General Support
$wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $field = $event->object; if($this->process != 'ProcessPageEdit') return; $page = $this->process->getPage(); //... BTW, it would be better to hook a more specific inputfield render rather than just Inputfield::render. So something like InputfieldPageTable::render or whatever inputfield type you are targeting. -
@Tom., members of the PW community might be able to help with your issue if you can isolate the conditions that cause it and list steps for reproducing the issue. In the GitHub issue under "Steps to reproduce the issue" you just say... ...which really does not make for a useful bug report.
-
Excluding a past event from a PageReference field after it's been chosen
Robin S replied to a-ok's topic in General Support
It is a public method of the FieldtypePage class. See the description of the arguments in the DocBlock. Not sure. It works for me. But if you're not going to be changing the conditions for selectable pages often then you can just check the template and date in the foreach instead. There is no performance reason to not use a foreach. It's not like a $pages->find() selector where the database is involved. When you do anything with the value of a Page Reference field the entire PageArray (aka WireArray) is loaded (more about that here) and methods like find() or filter() are just foreaching the WireArray internally anyway.