Verified Commit 492062df authored by Dave Long's avatar Dave Long
Browse files

Issue #3206643 by fjgarlin, Lal_, AJV009, quietone, benjifisher, mohit_aghera,...

Issue #3206643 by fjgarlin, Lal_, AJV009, quietone, benjifisher, mohit_aghera, larowlan, VladimirAus, mherchel, xjm, alexpott, Rishabh Vishwakarma, ckrina, rkoller, Gábor Hojtsy, smustgrave, AkshayAdhav, hestenet, irinaz, AaronMcHale, andrewmacpherson, longwave, catch, shaal, nod_, drumm: Project messaging channel in core (as experimental)
parent 60bd67fa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -358,6 +358,7 @@ drupallink
drupalmedia
drupalmediaediting
drupalmediatoolbar
drupalorg
drupaltest
druplicon
drush
+6 −0
Original line number Diff line number Diff line
name: Announcements
type: module
description: Displays announcements from the Drupal community.
version: VERSION
package: Core (Experimental)
lifecycle: experimental
+17 −0
Original line number Diff line number Diff line
drupal.announcements_feed.dialog:
  version: VERSION
  css:
    component:
      css/announcements_feed.dialog.css: {}

drupal.announcements_feed.toolbar:
  version: VERSION
  css:
    component:
      css/announcements_feed.toolbar.css: {}

drupal.announcements_feed.page:
  version: VERSION
  css:
    component:
      css/announcements_feed.page.css: {}
+104 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Fetch community announcements from www.drupal.org feed.
 */

use Drupal\announcements_feed\RenderCallbacks;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function announcements_feed_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.announcements_feed':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Announcements module displays announcements from the Drupal community. For more information, see the <a href=":documentation">online documentation for the Announcements module</a>.', [':documentation' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/announcements-feed']) . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl><dt>' . t('Accessing announcements') . '</dt>';
      $output .= '<dd>' . t('Users with the "View drupal.org announcements" permission may click on the "Announcements" item in the administration toolbar to see all announcements relevant to the Drupal version of your site.') . '</dd>';
      $output .= '</dl>';
      return $output;
  }
}

/**
 * Implements hook_toolbar().
 */
function announcements_feed_toolbar() {
  if (!\Drupal::currentUser()->hasPermission('access announcements')) {
    return [
      '#cache' => ['contexts' => ['user.permissions']],
    ];
  }
  $items['announcement'] = [
    '#type' => 'toolbar_item',
    'tab' => [
      '#lazy_builder' => [
        'announcements_feed.lazy_builders:renderAnnouncements',
        [],
      ],
      '#create_placeholder' => TRUE,
      '#cache' => [
        'tags' => [
          'announcements_feed:feed',
        ],
      ],
    ],
    '#wrapper_attributes' => [
      'class' => ['announce-toolbar-tab'],
    ],
    '#cache' => ['contexts' => ['user.permissions']],
    '#weight' => 3399,
  ];

  // \Drupal\toolbar\Element\ToolbarItem::preRenderToolbarItem adds an
  // #attributes property to each toolbar item's tab child automatically.
  // Lazy builders don't support an #attributes property so we need to
  // add another render callback to remove the #attributes property. We start by
  // adding the defaults, and then we append our own pre render callback.
  $items['announcement'] += \Drupal::service('plugin.manager.element_info')->getInfo('toolbar_item');
  $items['announcement']['#pre_render'][] = [RenderCallbacks::class, 'removeTabAttributes'];
  return $items;
}

/**
 * Implements hook_theme().
 */
function announcements_feed_theme($existing, $type, $theme, $path) {
  return [
    'announcements_feed' => [
      'variables' => [
        'featured' => NULL,
        'standard' => NULL,
        'count' => 0,
        'feed_link' => '',
      ],
    ],
    'announcements_feed_admin' => [
      'variables' => [
        'featured' => NULL,
        'standard' => NULL,
        'count' => 0,
        'feed_link' => '',
      ],
    ],
  ];
}

/**
 * Implements hook_cron().
 */
function announcements_feed_cron() {
  $config = \Drupal::config('announcements_feed.settings');
  $interval = $config->get('cron_interval');
  $last_check = \Drupal::state()->get('announcements_feed.last_fetch', 0);
  $time = \Drupal::time()->getRequestTime();
  if (($time - $last_check) > $interval) {
    \Drupal::service('announcements_feed.fetcher')->fetch(TRUE);
    \Drupal::state()->set('announcements_feed.last_fetch', $time);
  }
}
+2 −0
Original line number Diff line number Diff line
access announcements:
  title: 'View official announcements related to Drupal'
Loading