Jump to content

Page Table Howto


Gideon So

Recommended Posts

I can add new pages from the parent using the Add New button with no errors. I have checked the inputfield set up and there are no errors there too.

I have debug enabled, but I can't see any errors. I am surely missing something simple...

Link to comment
Share on other sites

  • 3 weeks later...

I am having a problem with Page Tables. I am using 2.5.14 dev on my local WAMP install, but I remember having similar issues with the latest master version. I set up my templates: entry-image and entry-text; these are what I want to control with my Page Table field called entry_sections. I add entry_sections to my work-entry template and I see the "Add entry-image" and "Add entry-text" buttons at the bottom of the Page Table field. When I click add entry-image, the modal window says "entry-image" as it should. But, when I click the button to add entry-text, the modal window says "entry-image". As a test, I went to the entry_sections field and removed the entry-image template. When I go back to the page, it still only wants to add "entry-image" even though the only option is to add entry-text.

Ideas anyone?? Thanks.

Link to comment
Share on other sites

  • 2 weeks later...

Sure it’s possible. I’d love to see a more page-field-like PageTable, actually. Here is a (really, seriously) half-assed module that lets you add a page to a PageTable field. Be aware, when you remove your page from the field, it will trash the entire page just like the standard PageTable does. Do NOT use this anywhere but in a testing environment.

It also has a hard coded template that you shoult probably change to whatever your PageTable accepts.

$this->addHookAfter('InputfieldPageTable::render', $this, 'PageTableRender');
public function PageTableRender($event) {
    $pageTable = $event->object;

    $out = "<select name='{$pageTable->name}_addcustom'>";
    $pages = $this->pages->find('template=PAGETABLETEMPLATE'); //change this
    foreach ($pages as $p) {
        $out .= "<option value='{$p->id}'>{$p->title}</option>";
    }
    $out .= '</select>';
    
    $out .= "<script>
                $(document).ready(function(){
                    $('select[name=\"{$pageTable->name}_addcustom\"]').change(addPage);
                    
                    function addPage() {
                        var input = $('input[name=\"{$pageTable->name}\"]');
                        var container = input.siblings('.InputfieldPageTableContainer');
                        var dataurl = container.attr('data-url');
                        
                        var pageid = $('select[name=\"{$pageTable->name}_addcustom\"]').val();
                        
                        var ajaxURL = dataurl + '&InputfieldPageTableAdd=' + pageid;
                        
                        $.get(ajaxURL, function(data){
                            container.html(data);
                            container.effect('highlight', 1000);
                        });
                        
                        alert('wtf did you do');
                    }
                });
            </script>";     

    $event->return .= $out;
}
As you can see, the heavy lifting in the PageTable field is done via Ajax. Maybe it’s a starting point. I really need to go to bed :P
  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Is there a way to prevent deleting a PageTable item for a user.

It would be nice if it could be set on a user / template base.

I know a hook is the way to do it but setting this up myself is unfortunately not within my reach.

Any help would be appreciated

Link to comment
Share on other sites

Thank for your quick reply.

In the template "acces tab" I cannot find the option to prevent a user to delete a page. I searched all the other tabs but could not find it.

But in my case the editor does not have the right to delete pages (role setting) so he should not be able to delete the pagetabel item.

Link to comment
Share on other sites

Here is something I hacked together quickly for automatically adding new child pages to the pagetable field. This is only if you are using the page as the parent. It also handles deletion of items if they are trashed externally. I also disabled the internal check for orphans - because they have been automatically added already, there is no need for the "Children were found that may be added to this table. Check the box next to any you would like to add." option.

I seems to be working great here, but please test carefully!!

Add this to your admin.php file:

wire()->addHookBefore('InputfieldPageTable::render', function($event) {
    $pp = wire('pages')->get(wire('input')->get->id);
    $ptf = $event->object;

    //remove pages from pagetable field if they were externally trashed
    foreach($pp->{$ptf->name} as $item) {
        if($item->is(Page::statusTrash)) $pp->{$ptf->name}->remove($item);
    }

    //add pages to pagetable field if they were created externally
    foreach($pp->children as $child) {
        if(!$ptf->has($child->id)) {
            $pp->{$ptf->name}->add($child);
            $pp->of(false);
            $pp->save($ptf->name);
        }
    }

    //reset orphans property so that we don't get a message asking to add new pages that are now already automatically added
    $ptf->setOrphans(new pageArray());
});
  • Like 13
  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...
  • 3 weeks later...

I found a bug:


        if(!$ptf->has($child->id)) {
            $pp->{$ptf->name}->add($child);
            $pp->of(false);
            $pp->save($ptf->name);
        }

Should be:


        if(!$pp->{$ptf->name}->has($child)) {
            $pp->{$ptf->name}->add($child);
            $pp->of(false);
            $pp->save($ptf->name);
        }

It was re-writing the PageTable items every time, which made it impossible to reorder items.

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

Just a shot question...

How can i get the first item of a PageTable field with a specific template

pages are stored central hidden admin page...and i nedd this in a function to get the first text field of a multiple contenttype PageTable

example:

PageTable field = pt_contents

-> i wanna get access to the fieldentries of the first item of pt_contents with the template part_text?

i'm little stucked...;)

Link to comment
Share on other sites

Thank you very much - works great - always getting an error with ->first() or something else...since it is not needed and with get the first item with given selector is there!

I'm working on a kind of contentbuilder PageTable that works as replacement for the main body field with a stripped CKE and own templates for the contentblocks...and i used to get some kind of teaser so i was searching for the first text element in the different blocks!

Thanks again - regards mr-fan

Link to comment
Share on other sites

  • 4 months later...
  • 1 month later...

One Question on PW Link Dialog - How could i prevent that PageTable Items like part_text, part_image ...get listed in this dialog.

I've a kind of blockbuilder running with PageTable and have the Pages under a hidden Parent in the tree. But pages are listet.

Could i hook in the link dialog and exclude the PageTable Templates?

Best Regards mr-fan

Link to comment
Share on other sites

yes - i know this is a bit tricky there.. on a page field where i link "see also" kind pages i have full control about the ouput.

But on the PW Link plugin all pages are there - pagetable pages, too...

The search suggestion should don't show something like this:

Term: >about<

Autocomplete:

/about/something/

/about/

/contentblocks/about-us/

while contentblocks is a hidden parent page for the contentblockpages - that for shure not hidden.

I've searched the forum - i had some experience in changing the PWImage plugin to bind it to a specific parent page (for central image handling) but with help from adrian.

Can you give me a hint where to hook/start right?

Best regards mr-fan

Link to comment
Share on other sites

The autocomplete field is a bit of a beast on it's own because it's internally using processwire's search (imho. in a lack of other ajax api endpoints) I'm not sure how well this thing can be configured. But it should certainly not reveal hidden pages (to unauthorized users), which I would consider a bug.

Link to comment
Share on other sites

I was afraid that... :-[ 

Configuration for now is a have page

/contentblocks/ as hidden parent with no edit rights to the editors group

/contentblocks/xxxxx/  childpages with edit/view rights for editors

The parent is under a normal /settings/ page in the pagetree. Would it be better if the blocks are under the admin branch of the tree - may this is my issue?

Link to comment
Share on other sites

The search suggestion should don't show something like this:

@mr-fan,

This actually should be quite simple. Add an after hook on: ProcessPageSearch::executeFor

and call this method:

    public function removeHiddenFromSearch($event) {
        $response = $event->return;
        $responseArray = json_decode($response, true);
        $matches = $responseArray['matches'];
        $i=0;
        foreach($matches as $match) {
            if($this->pages->get($match['id'])->isHidden()) {
                unset($matches[$i]);
            }
            $i++;
        }
        $responseArray['matches'] = $matches;
        $event->return = json_encode($responseArray);
    }

This will remove all hidden pages from the results, but I get the feeling the pages themselves are not actually hidden, just the "Settings" parent. Is that correct? In that case change "isHidden()" to check if the page is a child of the "Settings" parent - I'll let you figure that out :)

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...