Jump to content

neosin

Members
  • Posts

    107
  • Joined

  • Last visited

Posts posted by neosin

  1. This issue is related to the backend only, not frontend templates.

    I have a pagefield called "programs_list" that displays a list of "programs" and this works fine however the ID's assigned to those items are "PW" page id's.

    How can I match a selected item to a custom field value instead of the default PW ID ?

    I've imported a large volume of data using the API and this data has a field called "program_id" that I need to match with the "programs_list" pagefield.

    The "programs_list" pagefield uses a template that contains a "legacy_id" field that I need to match up with the imported datas "program_id" so that it shows the correct item as being selected.

    Any examples on how to go about achieving the desired result would be much appreciated.

    thanks in advance

     

     

  2. 7 minutes ago, adrian said:

    Are the other languages active? on the settings tab of the page? You should set the status for each language to active during the import. Or after the fact you can do with the AdminActions module's "Page Active Languages Batcher" feature.

     

    aha yes I see that the "active" is not checked for the url of the french versions.

    I thought this was only for the URL when visiting that link, so I was under the impression the data would still be accessible/visible.

    thank you for the quick diagnosis much appreciated

     

    if anyone else is curious or needs details on setting active by API

     

    • Like 1
  3. I've imported a batch of data but for whatever reason when switching language on the site, I can't get the other language data to appear.

    The data exists and is editable in the admin but even editing & re-saving the record data has no effect to make it display.

    To do a test I created a page along the imported records in the admin under the parent I need it in and this page displays proper data in both languages.

    There must be a setting or field required that I forgot to add to make it work properly?

    Here is the import script loop

    $fr = $languages->get("fr");
    while($row = $result->fetch_assoc()) {
    	$program_id = wire("sanitizer")->text($row['program_id']);
    	$p = wire('pages')->get("template=legacy-programs,program_id={$program_id}"); 
    	$title_en = \Encoding::toUTF8($row['title_en']);
    	$title_fr = \Encoding::toUTF8($row['title_fr']);
    
    	if($p->id > 0){
    	  // Item exists, was it updated?
    	  if($p->date_updated != date('Y-m-d H:i',strtotime($today))){
    		  $p->of(false);
    		  $p->title = $title_en;
    		  $p->setLanguageValue($fr,'title',$title_fr);
    		  $p->program_id = $program_id;
    		  $p->setName($program_id);
    		  $p->setName($program_id, 'fr');                                           
    		  $p->save();
    	  }else{
    		  continue;
    	  }
    	}else{
    	  // Item doesn't exists, create it.
    	  $p = new Page();
    	  $p->template = "legacy-programs";
    	  $p->parent_id = 2245;
    	  $p->of(false);
    	  $p->title = $title_en;
    	  $p->setLanguageValue($fr,'title',$title_fr);
    	  $p->program_id = $program_id;
    	  $p->setName($program_id);
    	  $p->setName($program_id, 'fr');
    	  $p->save();
    	}
    }

    This work great in the admin, I can see the data and edit it but for some reason it will not display the french version fields on the front end.

    The records show that they are published and visible/searchable in record settings.

  4. @maxf5 it gives error "Call to a member function setLanguageValue() on string"  but we are using $p->of(false); so it should be an array... I am confused

    This is the update code which is giving this error now

    while($row = $result->fetch_assoc()) {
    	$fr = $languages->get("fr");  
    	$p->of(false);
    
    	$p->title = $row['title_en'];
    	$p->title->setLanguageValue($fr, $row['title_fr']);
    	$p->summary = $row['description_en'];
    	$p->summary->setLanguageValue($fr, $row['description_fr']);
    	$p->save();
    }

     

  5. Hi all

    I am bootstraping PW to import large batches of data however I am having a hard time importing the alternate language using the suggested method

    I am using the language alternate field method as outlined here https://processwire.com/api/multi-language-support/multi-language-fields/#language-alternate-field-values

    here is the code  I am using and the issue is that the French fields do not populate at all. The English data is fine but for some reason the French does not get filled in.

    The name of the alt lang is "fr" and the title is "Français", so I assumed I could do $page->body_fr but this seems not to be the case?

    while($row = $result->fetch_assoc()) {	  
    	  $p = new Page();
    	  $p->template = "video-item";
    	  $p->parent_id = 1057;
    	  $p->of(false); // outputFormatting must be OFF
    	  $p->title = $row['title_en'];
    	  $p->title_fr = $row['title_fr'];
    	  $p->summary = $row['description_en'];
    	  $p->summary_fr = $row['description_fr'];
    	  $p->save();
    }

    The external database (non-PW) fields for French all exist and all have data.

    It seems if I have outputFormatting on or off makes no difference, initially I did not have it but after reading the link above I added it but it has no effect so far.

    What am I doing wrong?

  6. On 4/1/2018 at 7:35 AM, kongondo said:

    Depending on your use case, here's two other options

    1. Clone PageAutocomplete, rename the file and class, .e.g PageAutocompleteCustom, edit it to do what you need. The advantage here is portability, no need to Hook into anything, get to know the inner workings of ProcessWire (especially Pagefields, etc).

     thank you, I hadn't considered this possibility

  7. what would be the best way to use PageAutocomplete and have some curated results above the search result?

    For example a user searches for something and in the autocomplete list it shows results related to the search but also you could have a trigger to match some keyword and it will show at the top of the autocomplete results. How would this work in PW?

    The way to do it I think (again with my limited PW knowledge) would be to have a hidden page with children as "search triggers" and if there is a match of the user search then show the related child trigger pages at the top of the autocomplete. How do I hook into the autocomplete? Is there a hook for comparing the search term to a hidden pages children?

    thanks in advance & happy Easter weekend to all

  8. On 3/27/2018 at 12:37 PM, Jim Bailie said:

    Ajax - Send raw template only, without _main.php

    If I understand correctly, you want to send data from a template without using the _main file.

    To send data without using _main.php you can set this in the template itself.

    Open the template in PW and goto the "Files" tab and at the bottom right side you see "Append File" and under that is a checkbox which says "Disable automatic append of file: _main.php". Make sure to have that box checked.

    Now in your actual template file (example: ajax_out.php) you would put the header you want to use and just output as usual.

    header("Content-type: application/json");
    echo json_encode(array(
        "title" => $page->title,
        "message" => $page->body,
        "something" => "Lorem ipsum"
    ));

     

  9. Maybe this is by design?

    I created a input field type "select" and in the "selectable page" > "parents" I chose an option but now I want to remove it and use "template" instead.

    The issue I have is that I cannot remove the parent since there is no option to do so.

    I only want to use the "template" option, how can I remove the "parent" selected and only use "template"?

    it seems once I set a parent (for testing) there is no way to deselect using parents.

    However i am able to create fields with "selectable page > template" and no parent as long as I never choose a parent and save.5abd2ffcbbabf_Screenshot-2018-3-29EditFieldstream_encoder127001.png.0b3350a3a72a394caa12b232201d1300.png

    In the image above you can see I have "Encoders" set as the parent but I wish to remove this and only use the template. The problem is there is no way to remove the "encoders" parent once it has been selected, only can change the value not remove it completely.

  10. 3 hours ago, Robin S said:

    That is a method of the base Fieldtype class that all fieldtypes extend.

    ahh I see, is this documented somewhere?

    Looking at the captain hooks page (https://processwire.com/api/hooks/captain-hook/) under "/wire/modules/Fieldtype/ FieldtypePageTitle.module" , this is not clear.

    It only shows 1 method "getCompatibleFieldtypes" for this, the other FieldType modules have the wakeupValue listed though.

    @Robin S ps. ty for your patience and help

     

  11. @teppo thank you, evidently I am unnecessarily over-complicating things for myself due to my lack of knowledge of PW intricate functionalities. I will build a smaller site to familiarize myself more with the system and read every single tutorial and doc I can find. I was "wishfully" assuming that I could jump right in and quickly rebuild something like CNN/Youtube/twitch in PW in a short amount of time.

    On a side note, according to the captain hooks page, FieldtypePageTitle does not have a "wakeupValue" function, does this explain why Robin S example code above doesn't work for me, or is wakeupvalue inherited from somewhere else for FieldTypePageTitle?

  12. 6 minutes ago, LostKobrakai said:

    There is no such thing as "permissions for a page" in processwire. Permissions are granted to templates, which is why editing permissions makes most sense in the template edit section. 

    So if I understand correctly, I would need to duplicate "basic-page" template, set the child to the new template then set the permissions for the new template, as opposed to simply setting a permission/role directly in the child page which uses the same template as the parent currently or even having a list of all pages regardless of template where you can set permissions/roles.

    So imagine this scenario - 100 child pages each requiring custom permission but all use same template as "home", they would each need a copy of the "basic-page" template and have the roles/permissions set for each one as needed, so now you have 100 templates that all do the same thing in your admin just different permissions. Instead imagine they can all use "basic-page" (1 template) and you assign the role/permission directly in the child pages itself.

    Which option is cleaner?

     

  13. 7 hours ago, Robin S said:

    Add the following to the top of /site/templates/admin.php

    
    if($user->hasRole('some_role')) { // Replace 'some_role' with the role you want to customise the page list for
        $wire->addHookAfter('FieldtypePageTitle::wakeupValue', function(HookEvent $event) {
            $page = $event->arguments(0);
            // Should be able to match 'Pages' page by ID
            if($page->id === 3) {
                // Change 'Pages' to 'Streams'
                $event->return = 'Streams';
            }
        });
        $wire->addHookBefore('ProcessPageList::execute', function(HookEvent $event) {
            $ppl = $event->object;
            // Start ProcessPageList from a particular parent page
            $ppl->id = 1234; // The ID of the 'Streams' page
        });
    }

    If you are already logged in as this role, log out and then log in again to clear the cached top-level menu.

    This causes a strange bug with ajax on the admin side besides not working.

    When I have this code in admin.php it does not clear "ajax notices".

    I was switching between user accounts with different roles to test this code and I noticed that no matter what I did, failed login attempts ajax notices never cleared. So each login fail by another user would display each time the admin logged in even if they cleared the notices before logging out and back in.

    When I comment out/remove this code, the ajax notices clear as intended for admin. I have no idea what is going on here.

  14. 1 hour ago, alxndre said:

    Usually we use the finder (Pages > Find) and saving bookmarks for commonly used filters. Other times, we create custom module for this if additional functionality is needed.

    Thank you, it would be cool if the finder view was a settings option for parent pages to display the paginated list automatically or not for its children.

    This brings up an important issue then for my original post, if pages is not available to certain roles, then how would a user even get access to the finder? I assume that I would have to add another hook to specifically add "finder" to the admin nav menu.

    So now I am thinking that the solution to hide/replace pages will not be the way to go because the users would absolutely need to use "Finder" to paginate and find what they are looking for since pagination is not already part of page lists.

    Is PW geared more for single user or very small team projects with simple content requirements? I ask because I find it unusual that there would be so much "work arounds" required to customize the admin for what appears to be simple things like adding new menus and paginating content lists and things like that which are pretty standard in most CMS nowdays.

    I am seeing that I have 2 options if I choose to keep working with PW:

    1.  Override lots of the current admin functionality using hooks/custom modules to change basic things like menus/pagination/etc.
    2.  Create an entirely custom admin for my needs, bypassing the current admin completely using custom classes/modules/etc or an entirely different framework altogether but keeping PW for the wonderful pages functionality. But this entirely defeats the purpose of using PW as a CMS in the first place.

    Ideally PW would allow by default:

    1.  For an admin to select a page in the pages settings, to appear as a menu item in the admin top nav.
    2.  For an admin to select if a pages children should display as paginated and by how much.
    3.  For an admin to set in a page what admin roles can access/edit/etc this page in and/or its children directly in the page (not using the roles/permissions nav link). It is counter-intuitive to have to leave the page and visit "roles/permissions" to set permissions for a page. Also pages under "Home" appear to inherit the home permission so kind of useless at the moment if I have 2 roles one to edit the home page and one to edit streams but they can both edit each others content even if that is not the required permissions since "streams" is a child of "home". 

    Don't get me wrong, I like PW but based on what I have understood/learned about PW in the last week it seems that it is more geared for small teams/small projects if you want to use it as is "out of the box" with minimal to no tweaking.

×
×
  • Create New...