Elgg 6.3.3 - Pages plugin

Hello,

How can I make the pages in the pages plugin always "private" and remove the access dropdown list ?

What do I need to change in the code ?

Chris

  • I assume you mean 'Write access' field in the form.

    make the pages in the pages plugin always "private"

    You need to create an event in your custom plugin:

    elgg-plugin.php

    'events' => [
            'access:collections:write' => [
                'user' => [
                    '\MyPlugin\Pages\Views::onlyAccessPrivate' => [],
                ],
            ],
    ],

    MyPlugin\Pages\Views.php

    <?php
    
    namespace MyPlugin\Pages;
    
    
    class Views {
    
        public static function onlyAccessPrivate(\Elgg\Event $event) {
            
            $input_params = $event->getParam('input_params');
            $return_value = $event->getValue();
            
            if (empty($input_params)) {
                return;
            }
            
            if (elgg_extract('entity_subtype', $input_params) !== 'page') {
                return;
            }
        
            if (elgg_extract('purpose', $input_params) !== 'write') {
                return;
            }
            
            unset($return_value[ACCESS_PUBLIC]);
            unset($return_value[3]);
            unset($return_value[ACCESS_LOGGED_IN]);
            
            return $return_value;
        }
    }

    remove the access dropdown list 

    You need to override \mod\pages\views\default\forms\pages\edit.php in your custom plugin 

    In \mod\my_plugin\views\default\forms\pages\edit.php edit this code:

    switch ($name) {
            case 'access_id':
            case 'write_access_id':

    On this:

    switch ($name) {
            case 'access_id':
    
  • Thank you Nikolai.

    It works well !

    But the writing dropdown list remains visible and displays "private".

    Is there a way to hide it?

    (I clear the cache before each test I run.)

  • Forgot about saving...

    Add a new event in your custom plugin:

    elgg-plugin.php

    'events' => [
            'fields' => [
                'object:page' => [
                    \MyPlugin\Pages\FieldsHandler::class => ['priority' => 501],
                ],
            ],
    ],

    Create a new file \mod\my_plugin\classes\MyPlugin\Pages\FieldsHandler.php

    <?php
    
    namespace MyPlugin\Pages;
    
    class FieldsHandler {
        
        public function __invoke(\Elgg\Event $event): ?array {
            $result = $event->getValue();
            
            foreach ($result as $k => $field) {
                if (elgg_extract('name', $field) === 'write_access_id') {
                    unset($result[$k]);
                }
            }
            
            $result = array_values($result);
            
            return $result;
        }
    }

    Note: your custom plugin must be placed under 'Pages' plugin on the /admin/plugins page.

     

     

  • Absolutely perfect !

    Thanks again.