Jump to content

a-ok

Members
  • Posts

    812
  • Joined

  • Last visited

Posts posted by a-ok

  1. 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');

     

  2. 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).

  3. 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" }`

  4. 3 hours ago, BitPoet said:

    The builtin feature means that PW parses the HTML for named anchors, and if found, adds a "Select Anchor" select box at the top right. Did you remove the if($page->template...) line in my example? This was just meant for demonstration of limiting the functionality to a certain template.

    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.

     

    Screenshot 2020-03-08 at 16.31.36.jpg

  5. 21 hours ago, BitPoet said:

    Here's a quick and dirty demo how to add your own anchors to the builtin anchor feature of ProcessPageEditLink. No form manipulation shenanigans and no JS either. ?

    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?

  6.  

    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>";
    
    });

     

  7. 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>";
    
    });

     

  8. 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;
    
    }

     

  9. 10 hours ago, Robin S said:

    Thanks, but not necessary. Pretty much all my modules get created because I have a need for them in work that I get paid to do, and it doesn't cost me anything to make them available for others to use too.

    You are why the internet thrives. Thanks, Robin.

    • Like 2
  10. On 2/14/2020 at 9:37 PM, a-ok said:

    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?

    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?

    • Like 1
  11. 21 minutes ago, MoritzLost said:
    • Have you tried setting the default value for the Selector string to something more permissive so that it allows all pages? Not sure why the overwrite is not working, but this could be a workaround.
    •  

    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!

  12. 28 minutes ago, dragan said:

    I've read your post now three times, and I'm still not sure what you try to achieve.

    Your selector is basically useless, since there can only be one page with template=home. (and sorting one single page is... useless too)

    Did you mean has_parent=home?

    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)

  13. 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.

  14. 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?

  15. 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");
    		}
    
    	}

     

  16. 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?

×
×
  • Create New...