-
Posts
812 -
Joined
-
Last visited
Posts posted by a-ok
-
-
I managed to work this out by doing the following... might be useful for others.
function eSubmissionImageToRepeater($event) { $page = $event->arguments(0); if ($page->template->name == 'events-detail') { // What's On detail if (count($page->flexible_content) <= 1 && $page->flexible_content->first()->type == 'text') { $featuredImage = $page->featured_image->first(); $flexibleContentRepeater = $page->flexible_content->getNew(); $flexibleContentRepeater->of(false); $flexibleContentRepeater->save(); $flexibleContentRepeater->repeater_matrix_type = 2; // Image(s) $flexibleContentRepeater->save(); $flexibleContentRepeater->flexible_content_images->add($featuredImage->httpUrl); $flexibleContentRepeater->save(); $flexibleContentRepeaterID = $flexibleContentRepeater->parent_id; $firstItem = $event->pages->find("parent_id=$flexibleContentRepeaterID")->first(); $lastItem = $event->pages->find("parent_id=$flexibleContentRepeaterID")->last(); $event->pages->insertBefore($lastItem, $firstItem); } } } if ($user->hasRole('e-submission')) { // Ony required for 'e-submissions' $wire->addHookAfter("Pages::save", null, "eSubmissionImageToRepeater"); }
-
Anyone got any other ideas?
This seems to work:
$flexibleContentRepeater->flexible_content_images->add("https://i.stack.imgur.com/bn9pu.png");
But this doesn't (bd'ing $page->featured_image->httpUrl returns the correct full URL...)
$flexibleContentRepeater->flexible_content_images->add($page->featured_image->httpUrl);
EDIT
I think it's due to the ->op(false) which makes the featured_image field an array and thus this works...
$featuredImage = $page->featured_image->first();
-
7 hours ago, elabx said:
Try setting the output formatting for the $flexibleContentRepeater repeater matrix item (which is a page!)
$flexibleContentRepeater->of(false);
I also think you shouldn't be saving the page inside the hook:
Thanks! I think you're right re saving the page... I've removed that. The output formatting addition hasn't solved this though; still a blank image field.
Hmm...
-
Hi folks,
I'm wanting to take an Image field and add the same image as the first row of a RepeaterMatrix field. If RepeaterField field rows already exist, it should shift it to the first row, and if the image has already been added then it shouldn't re-add it. I guess I could double check the image URL on this to prevent this?
Anyway, I thought this would work... it's adding in a RepeaterMatrix row of the requested type but the image isn't being added.
function eSubmissionImageToRepeater($event) { $page = $event->arguments(0); if ($page->template->name == 'events-detail') { // What's On detail $flexibleContentRepeater = $page->flexible_content->getNew(); $flexibleContentRepeater->save(); $flexibleContentRepeater->repeater_matrix_type = 2; $flexibleContentRepeater->save(); $flexibleContentRepeater->flexible_content_images->add($page->featured_image->httpUrl); $flexibleContentRepeater->flexible_content_images->save(); $flexibleContentRepeater->save(); $page->save(); } } $wire->addHookAfter("Pages::save", null, "eSubmissionImageToRepeater");
Any help?
-
-
1 hour ago, elabx said:
Maybe it's a permission issue in the repeater matrix template used by the repeater matrix field?? Though makes me wonder why it works on Text type because that one uses the same template as the other types.
Yeah I thought the same
-
Hi folks,
I have a contributors specific role set up on PW which allows them to add and edit only their own page(s) to a parent page (Events > event) and have managed to do this by setting up specific template permissions but also include the following in my ready.php file (so they only see their own pages)
function eSubmissionPermissions($event) { $page = $event->object; if (!$event->return) return; if ($page->template->name == "events-detail" && $event->user->id !== $page->createdUser->id) { $event->return = false; } else { $event->return = true; } } if ($user->hasRole('e-submission')) { // Ony required for 'e-submissions' $wire->addHookAfter("Page::listable", null, "eSubmissionPermissions"); }
This all works fine but there's one issue. I have a RepeaterMatrix set up for flexible content and the user/role can add to this fine if the content is text but when they go to add an image it states 'You don't have access to edit' when adding the image. Is there anything extra I should be doing in order to allow this? They can add an image fine that isn't in the RepeaterMatrix. I am using PW 3.0.80. It's also maybe worth noting that I am not allowing this user to publish pages (only save them) as this will be done by the admin on successful admission.
-
Is there a way, without editing the module itself, to change the font sizes set in the CKEditor for h1, h2, h3 etc. They're just too big in proportion to the rest of the text. I'd like to be able to do it without amending the module in case of any updates.
Any thoughts?
-
6 minutes ago, elabx said:
Doing this myself right now in a project, and very weird what's happening to you because I'm also using the table field inside a RepeatrMatrix and I'm not having any issues with adding rows.
It may have to do with having AJAX set on the repeater.
- 1
-
3 minutes ago, elabx said:
Don't think this is possible because Table field uses it's own schema and adds a database column per table column, so changing it in the field would change it to all fields it is instantiated. The quickest idea I have to hack around this is to use RuntimeMarkup field and render your custom inputfield using jQuery datatables or something simliar and save it's data in a hidden text field).
Hmm it's okay actually because I can just use the first row as the thead and then the rest can follow and I can style the first row accordingly.
However upon adding the table to a repeater, when I try to add a row... it doesn't work. It's hashed in the URL when clicking so I'm guessing some JS isn't firing/is missing because it's in a repeater?
-
I'm looking at using ProFields Table for a specific layout. An attached image as an example. The client should be able to add as many tables as they want, and as many table rows with the option to change the thead titles.
My thought was to put a table in a repeater field and then use ProFields Table. This is generally okay but the only issue is that the table headers (theads) aren't fixed and need to be changed also. Any thoughts on changing the text for these?
Thanks!
-
Is there any documentation on turning an array into a WireArray? ->makeNew() doesn’t accept arrays.
-
58 minutes ago, kongondo said:
You basically have two choices
- Convert the PageArray into a regular array OR
- Convert the social media array into a WireArray (e.g. each to be a WireData which you throw into one WireArray)
#2 will give you the advantage of easily sorting by your custom date field. I am not sure though if a WireArray can be combined with a PageArray just like that (although the latter is from a WireArray, so, yeah, maybe it is possible).
Edit:
Depending on your operations and size of the PageArray, since Page objects can be big, to have the best of both worlds (1 and 2), you can use explode as per @Zeka's suggestion, but convert that into a WireArray. Then, convert your social media array into a WireArray and add it to the first WireArray. You can then do your sorting by the custom date field. I don't know how much this will cost you in server resources though. Just a thought...
Thanks for this. I didn't know you convert it into a WireArray tbh. This is what I currently have, which seems okay, but when I come to thinking about pagination... not sure how that'll work (so maybe WireArray is best if I can work it out). I haven't included my Instagram API fetch stuff here... just the variable.
$news = $pages->find('parent=/news/, sort=-created, limit=16')->explode(['id', 'created', 'title', 'url', 'images', 'summary_text']); $instagrams = $instagram->getInstagramRecent(); $items = array_merge($news, $instagrams['data']); bd($items); foreach ($items as $key => $item) { if (isset($item['user']['id']) && $item['user']['id'] == '1907645821') { // Instagram post $sort[$key] = $item['caption']['created_time']; } else { // News article $sort[$key] = $item['created']; } } array_multisort($sort, SORT_DESC, $items); bd($items); if (isset($item['user']['id']) && $item['user']['id'] == '1907645821') { // Instagram post $type = 'Instagram'; $title = NULL; $image = $item['images']['standard_resolution']['url']; $text = '<p class="instagram">' . $item['caption']['text'] . '</p>'; $link = $item['link']; } else { // News article $type = 'News'; $title = $item['title']; foreach($item['images'] as $img) { $itemImage = $img->url; break; } $image = $itemImage; $text = $item['summary_text']; $link = $item['url']; }
-
4 minutes ago, Zeka said:
You can use explode method to get only need properties of pages, so you can equalize array structure of pages and items from the Instagram feed.
$x = pages('template=product')->explode(['id', 'created', 'title']); $y = getInstagramFeedArray(); $result = array_merge($x, $y);
Very nice! I guess this is the best way, right? PW API offers nothing related? Thank you!
-
Is it possible to combine a pageArray with a regular PHP array? I'm returning a list of news items from PW, which is fine, but I'm also returning Instagram and Twitter posts, from API endpoint URLs (which is JSON but I have converted to PHP arrays) and I'd like to then ultimately import them all into one big array then sort by a custom date field (that I'll build and store per loop) so you get a list of news items, Instagram posts and tweets all sorted by date.
Any thoughts on importing a pageArray and a regular PHP array? Should I be using $a->getArray(); then combining them?
Thanks!
-
7 hours ago, Robin S said:
You can use $pageimages->add() to add images to a field.
$page->image_field->add('/full/path/to/image.jpg');
...or...
$page->image_field->add('http://domain.com/url/to/image.jpg');
But seeing as you will probably want to replace the existing image while keeping the same name you might want to use the PW admin to drop the new image onto the existing one. Not sure if there is an equivalent for doing that via the API.
I guess I could use
$image->removeVariations()
or even https://modules.processwire.com/modules/pageimage-remove-variations/
-
2 hours ago, Robin S said:
It's not sRGB.
Perhaps consider setting up a batch process in Photoshop to convert your supplied images to sRGB profile.
Setting individual imageSizerOptions in config like that doesn't work. There are two options for overriding individual options in /site/config.php...
$config->imageSizerOptions = array_merge($config->imageSizerOptions, ['upscaling' => false]);
...or...
$config->imageSizerOptions('upscaling', false);
This is all super helpful, Robin. I think that imageSizerOption setup is working now. Hero. Thank you.
As I'd need to re-upload all these images again to get the new options... is there a good way to do this via the API?
- 1
-
Another example. The blacks are very pixelated and fuzzy... even after setting sharpening to none, quality to 100 and default gamma to -1
-
If you click on these images you'll see the difference.
I'm also using this within my template:$image = $images->size(1600,800, ['upscaling' => true, 'cropping' => 'center', 'quality' => 100, 'sharpening' => 'none', 'defaultGamma' => -1]); // 2:1
I have now added the below to my config.php file instead of the above and reuploaded the image but it still shows the same quality/colour loss on the resized image.
$config->imageSizerOptions['sharpening'] = 'none'; $config->imageSizerOptions['quality'] = 100; $config->imageSizerOptions['defaultGamma'] = -1;
-
Sorry to bring this back up but I'm still fairly confused at how to resolve this.
See attached two images. One is the original uploaded and one is the resized version. I've checked the colour profile and it seems to be sRGB. I'm basically hoping that resized images are resized only (cropped) and no colour changes happen.
Any further thoughts?
-
@Robin S This is a GREAT explanation and is super appreciated. I totally get it... and now understand that some things don't work with in-memory selectors (modifying a PageFinder, in theory) – again I really appreciate your explanation.
- 3
-
10 minutes ago, Robin S said:
I don't think OR groups are supported at all in WireArray (therefore PageArray) methods - adding support for OR groups inside a single PageArray selector is what BitPoet's module above is all about.
But if you are doing what I suggested with find() and add() then you don't need the OR group parentheses. It's a different approach but should result in the same thing as OR groups inside a single selector.
Thanks again, Robin.
I thought, based on this page, https://processwire.com/api/selectors/#or-groups, that I was just using the OR groups inside a find() Page/WireArray? Or am I getting confused? Why would it work when doing one find() and not find()->find() for example?
-
Thanks, Robin. That makes sense!
Now the issue I seem to be experiencing is (when only have a single modifying query) is using an OR query...
For example...
$events = $pages->find("template=events-detail, events_detail_dates_final_date>=today"); $results = $events->find("(events_detail_dates_upcoming_start_date<=today)"); OR $results = $events->find("(events_detail_dates_upcoming_start_date<=1517174937,events_detail_dates_upcoming_start_date<=1517097600)");
Seems to remove all the items (itemsRemoved when using Tracey Debugger). If I remove the parenthesis from the top modifier, for example, it works fine but obviously the parenthesis is required for the OR group. Any further thoughts?
-
11 hours ago, Robin S said:
You could filter the PageArray more than once and add the results together. Actually, filter() is destructive so use find() instead.$results = $pagearray->find($selector_1)->add($pagearray->find($selector_2));
Thanks for this again, Robin. After looking at this I'm unsure if this is working...
$events = $pages->find("template=events-detail, events_detail_dates_final_date>=$today"); $calendar = $this->input->post->calendar; $query = $this->input->post->query; $results = $events->add($events->find("{$query}, {$calendar}"));
In this above example the $query could be the following (if upcoming start date is equal to or less than today)
events_detail_dates_upcoming_start_date<=1517171596
What result this is returning is the 'filtered' pages to the bottom off the original $events query... this is why the filter() option was good because it was removing any items that didn't match it the filter... not adding it to the original query. Any thoughts?
Running PW from an IP address
in General Support
Posted
Is it possible to run PW from an IP address before pointing the domain name at the server? The front end seems to be working okay but when I try to log in it just refreshes the page... is it possible to run it from an IP address (added to config as host too).