Skip to content

Instantly share code, notes, and snippets.

@somatonic
Last active June 18, 2018 13:27
Show Gist options
  • Select an option

  • Save somatonic/5595081 to your computer and use it in GitHub Desktop.

Select an option

Save somatonic/5595081 to your computer and use it in GitHub Desktop.

Revisions

  1. somatonic revised this gist May 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion HiddenAdminPages.module
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ class HiddenAdminPages extends WireData implements Module {
    $hidden = explode('|',$this->user->pagelist_hidden);

    // make sure it's an ajax request
    if($this->config->ajax && $_GET['render']){
    if($this->config->ajax){
    // manipulate the json returned and remove any pages found from array
    $json = json_decode($event->return, true);
    foreach($json['children'] as $key => $child){
  2. somatonic created this gist May 16, 2013.
    64 changes: 64 additions & 0 deletions HiddenAdminPages.module
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?php

    /**
    * UserWorkspaces
    *
    * Example module to hide page in the admin per user per page.
    *
    * ProcessWire 2.x
    * Copyright (C) 2010 by Ryan Cramer
    * Licensed under GNU/GPL v2, see LICENSE.TXT
    *
    * http://www.processwire.com
    * http://www.ryancramer.com
    *
    */

    class HiddenAdminPages extends WireData implements Module {

    public static function getModuleInfo() {

    return array(
    'title' => 'HiddenAdminPages',
    'version' => 100,
    'summary' => 'Example module to hide page in the admin per user per page.
    Add a page field "pagelist_hidden" with a PageListSelectMultiple input type
    to the user template. Select or add pages you want to hide in the admin.',
    'href' => '',
    'singular' => true,
    'autoload' => true
    );
    }


    public function init() {
    // only add hook only if the render parameter is set
    // (as used by ProcessPageList)
    if(!isset($_GET['render'])) return;

    if(!$this->templates->get("user")->hasField('pagelist_hidden')) return;
    if(!count($this->user->pagelist_hidden)) return;

    $this->addHookAfter('ProcessPageList::execute', $this, 'pageListHiddenPages');
    }


    public function pageListHiddenPages(HookEvent $event){

    // create an array with all id's of the page to exclude
    $hidden = explode('|',$this->user->pagelist_hidden);

    // make sure it's an ajax request
    if($this->config->ajax && $_GET['render']){
    // manipulate the json returned and remove any pages found from array
    $json = json_decode($event->return, true);
    foreach($json['children'] as $key => $child){
    if(in_array($child['id'],$hidden)) unset($json['children'][$key]);
    }
    $json['children'] = array_values($json['children']);
    $event->return = json_encode($json);
    }

    }

    }