-
Posts
812 -
Joined
-
Last visited
Everything posted by a-ok
-
I'm currently appending page names, with a specific template, with a date. This works fine but as I have multi-languages set up it only appears (unless my code is wrong) to be applying it to the default language page name. Any thoughts on where I'm going wrong? function customPageName(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'about-events-single') { $eventDate = date("dmY", $page->global_date_end); $pageName = wire()->sanitizer->pageName($page->title . '-' . $eventDate, true); $page->setOutputFormatting(false); $page->name = $pageName; } } wire()->addHookAfter('Pages::saveReady', null, 'customPageName');
-
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
Thanks so much for the help, @BitPoet. One final thing. Is it possible to keep the value of the select option as it is but change the label? My annotations list read as `#annotation-1020`, for example, which is super useful for some JS stuff I'll be doing with it, but ideally, for the user, it would be good to have these options a bit more descriptive. Any idea? I know you can add a label within the `InputfieldSelect::addOption()` method but obviously as I'm updating the anchors before it runs this I can't amend it. https://github.com/processwire/processwire/blob/51629cdd5f381d3881133baf83e1bd2d9306f867/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.module#L203 I guess having the option on this line to pass in a key/value (key would be the label) into the anchors array (otherwise label = null). -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
Looking at `ProcessPageEditLink.module` I feel like the code you've presented is correct; we're pushing these options and setting them to `wire('input')->get->anchors` so it should show... but it's not. Hmm. UPDATE I was using `addHookAfter` instead of `addHookBefore` ? -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
The annotations are generated from the repeater field `$page->textAnnotations` and then the idea is that the user would be able to select a repeater row (nothing more than a sanitised anchor of the title/ID field for each repeater row. So with my original code I was attempting to create a new `InputfieldSelect` field within `ProcessPageEditLink` with options for each `$page->textAnnotations` repeater row and it would output the link href as, for example, `#annotation-example-row-title` or `#annotation-1827`. I think we're on the same page BUT `$anchors` returns `array(3) { [0]=> string(11) "some_anchor" [1]=> string(12) "other_anchor" [2]=> string(12) "third_anchor" }` -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
Thanks again but I'm slightly confused. There's no 'Select Anchor' select box? What HTML does it parse? The template check is removed, yep. -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
Thanks for the help! What’s the built in anchor feature? I’ve added your code to test with but the options don’t appear when adding a link? Do I have to enable something else? -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
I also think I need to add the `$field` to the `$form` that already exists, rather than creating a new one. Any thoughts? -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
Think I've got it. Only thing would be the ability to add a data attribute to the link AND append to the other inputfields rather than replace them? $wire->addHookAfter('ProcessPageEditLink::execute', function(HookEvent $event) { $page = wire('pages')->get(wire('input')->get('id')); $form = $this->modules->get('InputfieldForm'); $form->attr('id', 'ProcessPageEditLinkForm'); $field = wire('modules')->get('InputfieldSelect'); $field->label = $this->_('Select annotation'); $field->attr('id+name', 'link_page_file'); $field->icon = 'link'; $annotations = array(); foreach($page->textAnnotations as $annotation) { $annotationClean = '#annotation--' . wire('sanitizer')->pageName($annotation->id); $annotations[$annotationClean] = $annotation->text; } asort($annotations); $field->addOption(''); // Allow unselect $field->addOptions($annotations); $form->add($field); // JS generated preview below selected link in popup $markup = '<span id="link_page_url_input"></span>'; $form->set('appendMarkup', $markup); $event->return = $form->render() . "<p class='detail ui-priority-secondary'><code id='link_markup'></code></p>"; }); -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
I think I've kinda got it, based on this post below, however I need to get the repeater elements on the page I'm editing and I can't seem to get the page? This is very rough and not tidied up at all, yet. $wire->addHookAfter('ProcessPageEditLink::execute', function(HookEvent $event) { $page = $event->object; $form = $this->modules->get("InputfieldForm"); $form->attr('id', 'ProcessPageEditLinkForm'); $field = wire('modules')->get('InputfieldSelect'); $field->label = $this->_("Select File"); $field->attr('id+name', 'link_page_file'); $field->icon = 'file-pdf-o'; var_dump($field->hasPage) ; $annotations = array(); foreach($page->textAnnotations as $annotation) { $annotation_clean = '#annotation--' . wire('sanitizer')->pageName($annotation->id); $annotations[$annotation_clean] = $annotation->text; } asort($annotations); var_dump($page); $options = $annotations; $field->addOption(''); // Allow unselect $field->addOptions($options); $form->add($field); // We need something like this to get the nice JS generated preview $markup = '<span id="link_page_url_input"></span>'; $form->set('appendMarkup', $markup); $event->return = $form->render() . "<p class='detail ui-priority-secondary'><code id='link_markup'></code></p>"; }); -
Adding a custom Page Reference field to ProcessPageEditLink
a-ok replied to a-ok's topic in General Support
I had written something like the following before, adding to `wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.module`, but I'd prefer to use a hook and avoid the custom JS if possible? public function ___executeAnnotations() { if(!$this->page->id) throw new WireException("A page id must be specified"); $annotations = $this->getAnnotations(); return wireEncodeJSON($annotations); } protected function getAnnotations() { $annotations = array(); if($this->page->id) foreach($this->page->speech_archive_detail_annotations as $annotation) { $annotation_clean = '#annotation--' . $this->wire('sanitizer')->pageName($annotation->id); $annotations[$annotation_clean] = $annotation->speech_archive_detail_annotations_title; } asort($annotations); return $annotations; } protected function getAnnotationsField() { $field = $this->modules->get("InputfieldSelect"); $field->label = $this->_("Select Annotation"); $field->attr('id+name', 'link_page_annotation'); $annotations = $this->getAnnotations(); $field->addOption(''); $field->addOptions($annotations); $field->collapsed = Inputfield::collapsedYes; if($this->page->id) $field->notes = $this->_('Showing annotations on page:') . ' **' . $this->page->url . '**'; $field->description = $this->_('Select the annotation from this page that you want to link to.'); $field->icon = 'comment-o'; return $field; } -
Is it possible to hook into ProcessPageEditLink in order to add a custom Page Reference field (for a Repeater on the same page!) for the user to link? This is specifically for annotations or footnotes so my thinking is the link would return a `data-annotation-id` of the repeater ID and row or similar. What are your thoughts?
-
You are why the internet thrives. Thanks, Robin.
-
Whoa, @Robin S that’s really awesome. Is there a way to donate to the module’s development or to yourself?
-
Just on this. I think it's due to the client duplicating a page (and thus not changing or 're-setting' the field)? Do you know if it's meant to work with duplicating the page?
-
This is a decent call. I could even write a hook to include all pages (unless I can do this with a selector) and then use the override then it'll only showing options from all pages. That'll work!
-
-
Sorry! The template=home part is just the default I set (I guess this could be in theory just be blank) but it’s the fact that after changing the selector to something else contextually within a template using the overrides it still looks to the one set as the field default (whereas it shouldn’t)
-
I have a 'Page Reference' field that I use for internal links. The default selectable pages for this field, is 'selector string' with the content `template=home, sort=sort`. This is just a filler as what I'm doing is setting overrides for the 'Details: Page field value type', 'Input: Input field type' and 'Input: Selector string' options within the template view so the fields returned are contextual. However, upon doing this I get this error when trying to save one of the pages that has the field with different options `PagesEditor: Error saving field "linkInternal" - Page 1079 is not valid for linkInternal (Page 1079 does not match findPagesSelector: template=home, sort=sort, id=1079)` Any thoughts? Is this not possible? I guess I could use hooks but thought this method at least kept the changes together.
-
@Robin S Thanks so much!
-
I've ran into some trouble where the 'Connect Page Fields' module has been working fine but on some recent additions it's not adding the connection (so I have to remove, save, re-add, save). Is there a way to run a query/hook to mass remove and re-add these, or force a re-check?
-
?
-
I'm attempting to include some code in the head.inc file that will check if the page is available in the user's location language and if so it'll redirect to that page. Obviously this isn't a great for UX but alas my client is keen. The only issue I need to overcome is if the user has already been redirected then don't do it for every page... store the fact that the user was redirected and don't do it again until the session has ended. Something like that. I have written the code below but a) I'm unsure this is the best way to do it and b) it seems to get stuck in a redirect loop (which I thought I'd avoided by my second session check). I'm using the ipapi.com to check the user's location. Any thoughts? if (!$session->get("lucentLightingRegion")) { bd($page->ipapiGetUserLocation()); $session->set("lucentLightingSessionRedirected", "false"); if ($page->ipapiGetUserLocation()['continent_code'] === 'NA') { $session->set("lucentLightingRegion", "NA"); if ($page->viewable('na')) { $url = $page->localUrl('na'); $session->redirect($url); } } else { $session->set("lucentLightingRegion", "INT"); if ($page->viewable('default')) { $url = $page->localUrl('default'); $session->redirect($url); } } } else { $sessionRegion = $session->get("lucentLightingRegion"); bd($sessionRegion); if ($page->viewable($sessionRegion) && $session->get("lucentLightingSessionRedirected") == "false") { $url = $page->localUrl($sessionRegion); $session->redirect($url); $session->set("lucentLightingSessionRedirected", "true"); } }
-
File upload field cutting file size and file content
a-ok replied to a-ok's topic in General Support
I've attached some images. I'm assuming it's an LCN server issue but they've stated they don't limit/cap anything. Same file on localhost and a DigitalOcean server upload fine whereas on LCN it jumps to 600kb and effectively breaks the file. -
If I'm uploading a .mp4 (could potentially be any file) to a file upload field and the file is 3mb but on uploading the file is 600kb and then the .mp4 is glitchy/plays for only a few seconds (in the browser) is it safe to assume something wrong is set on the server? I've never had this issue before (use DigitalOcean, mainly) but I'm using LCN for a client and this issue has only just occurred since migrating from my dev to LCN. Any thoughts?
-
[SOLVED] 301 redirect loop on all pages except homepage
a-ok replied to a-ok's topic in General Support
I just fixed it. Turns out `sudo a2enmod rewrite` wasn't enabled ?FOUR HOURS LATER. Sorry for wasting everyone's time.