Make Site Announcement Sticky

On a mobile device the menu link is often VERY difficult to activate while all other links are quite active.

I have created a Site Announcement:  

HOME    Activity    Blogs     Groups     Pages     Discussion     Bookmarks     Twitterlike     Members

That works just fine

Can I make a Site Announcement sticky? That is it cannot deleted by the user.

  • By the "menu link" I meant the link at the top/right that opens the menu. The links on the menu work fine.

    BTW this occurs on Android devices. I don't have an Apple device to check.

  • Thanks for your prompt response.

    Yes I am using that plugin when I posted the announcement, but don't see such an option.

  • You can override this file \views\default\object\site_announcement.php in your custom plugin and delete the 'mark' action for your sticky announcement:

    if($entity->guid == '777') {
         $content = elgg_view_image_block('', $content);
    } else {
          $content = elgg_view_image_block('', $content, ['image_alt' => $mark]);
    }

    where 777 is a GUID of your sticky announcement.

  • I found site_announcement.php
    I presume the quid is 91 because the edit link is https://elgg.serenitytoo.com/announcements/edit/91
    91 does not appear in the file:

    <?php
    /**
     * Display a single site announcement
     *
     * @uses $vars['entity'] the entity to show
     */

    $entity = elgg_extract('entity', $vars);
    if (!$entity instanceof \SiteAnnouncement) {
        return;
    }

    if (elgg_extract('full_view', $vars, false)) {
        
        $content = elgg_view('output/longtext', ['value' => $entity->description]);
        
        $announcement_type = $entity->announcement_type;
        
        $message_options = [
            'icon' => $entity->getMessageTypeIconName(),
            'class' => " site-announcement-" . $announcement_type
        ];
        
        switch ($announcement_type) {
            case 'attention':
                $message_type = 'warning';
                break;
            case 'error':
                $message_type = 'error';
                break;
            case 'info':
                $message_type = 'notice';
                break;
            default:
                $message_options['title'] = false;
                $message_type = 'success';
                break;
        }
        //error, success, warning, help, notice
        
        $mark = elgg_view('output/url', [
            'icon' => 'delete',
            'text' => false,
            'class' => 'site-announcements-mark',
            'title' => elgg_echo('site_announcements:menu:entity:mark'),
            'href' => elgg_generate_action_url('site_announcements/mark', ['guid' => $entity->guid]),
        ]);
        $content = elgg_view_image_block('', $content, ['image_alt' =>$mark ]);
        
        echo elgg_view_message($message_type, $content, $message_options);
    } else {
        $imprint = [
            'announcement_type' => [
                'icon_name' => $entity->getMessageTypeIconName(),
                'content' => $entity->getMessageTypeLabel(),
            ],
            'startdate' => [
                'icon_name' => 'calendar-alt-regular',
                'content' => elgg_echo('site_announcements:edit:startdate') . ': ' . elgg_view('output/date', [
                    'value' => $entity->startdate,
                    'format' => elgg_echo('friendlytime:date_format'),
                ]),
            ],
            'enddate' => [
                'icon_name' => 'calendar-times-regular',
                'content' => elgg_echo('site_announcements:edit:enddate') . ': ' . elgg_view('output/date', [
                    'value' => $entity->enddate,
                    'format' => elgg_echo('friendlytime:date_format'),
                ]),
            ],
        ];
        
        $params = [
            'entity' => $entity,
            'icon' => false,
            'content' => $entity->description,
            'access' => false,
            'byline' => false,
            'time' => false,
            'imprint' => $imprint,
        ];
        $params = $params + $vars;
        echo elgg_view('object/elements/summary', $params);
    }

     

     

  • In fact the phrase " if($entity->guid ==" does not appear in the elgg.serenitytoo.com  directory

  • You should create a custom plugin.

    Override the view of the existing file: copy from /mod/site_announcement/views/default/object/site_announcement.php to /mod/your_plugin/views/default/object/site_announcement.php

    Now edit this file in your plugin adding the mentioned code.

    Please read Elgg docs for more details.

  • Thanks I'll give it a try

  • OK did this before your: last reply

    zipped folder site_announcements in directory
    downloaded, unzipped, opened site_announcement.php
    added :

    if($entity->guid == '777') {
         $content = elgg_view_image_block('', $content);
    } else {
          $content = elgg_view_image_block('', $content, ['image_alt' => $mark]);
    }

    at the bottom of file

    What PRECISELY must I delete?

    Or was the whole thing I did wrong?