Robin S

  • Content count

  • Joined

  • Last visited

  • Days Won


Robin S last won the day on November 19

Robin S had the most liked content!

Community Reputation

3,049 Excellent

1 Follower

About Robin S

  • Rank
    Hero Member

Profile Information

  • Gender
  • Location
    New Zealand
  1. @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.
  2. 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) { //... }
  3. 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; });
  4. 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. 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. Use a new array for the purpose of sorting the raw unsorted results from your $pages->find() query: // Create new array to hold results for later sorting $sorted_results = array(); // For each of your $pages->find() results... foreach($results as $result) { // 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 result to the array, using the timestamp of the next upcoming date as the key $sorted_results[$next_upcoming->getUnformatted('events_detail_dates_start_date')] = $result; } // Sort the array by key (i.e. by timestamp) ksort($sorted_results); // Now loop over $sorted_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 key for the "our pick" results so they will appear where you want them once sorted by key.
  5. 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.
  6. 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/'; } //... 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
  7. If you are using Page Reference fields there is some limited support for this. See this post:
  8. 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; });
  9. 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/'; } //... 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.
  10. 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.
  11. 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.
  12. @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:
  13. @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.
  14. 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.
  15. $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.