You are here

paragraphs_demo.module in Paragraphs 8

File

modules/paragraphs_demo/paragraphs_demo.module
View source
<?php

/**
 * @file
 * Contains paragraphs_demo.module
 */
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function paragraphs_demo_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Help for the paragraphs demo module.
    case 'help.page.paragraphs_demo':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Paragraphs Demo module provides several <em>Paragraphs types</em> for the <a href=":paragraphs">Paragraphs module</a>, but no separate user interface. For more information, see the <a href=":online">online documentation for the Paragraphs module</a>.', [
        ':online' => 'https://www.drupal.org/node/2444881',
        ':paragraphs' => Url::fromRoute('help.page', [
          'name' => 'paragraphs',
        ])
          ->toString(),
      ]) . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dt>' . t('Changing demo Paragraphs types') . '</dt>';
      $output .= '<dd>' . t('Administrators can edit the provided <em>Paragraphs types</em> on the <a href=":paragraphs">Paragraphs types page</a> if the <a href=":field_ui">Field UI</a> module is enabled. For more information on fields and entities, see the <a href=":field">Field module help page</a>.', [
        ':paragraphs' => Url::fromRoute('entity.paragraphs_type.collection')
          ->toString(),
        ':field' => Url::fromRoute('help.page', [
          'name' => 'field',
        ])
          ->toString(),
        ':field_ui' => \Drupal::moduleHandler()
          ->moduleExists('field_ui') ? Url::fromRoute('help.page', [
          'name' => 'field_ui',
        ])
          ->toString() : '#',
      ]) . '</dd>';
      $output .= '<dt>' . t('Deleting demo Paragraphs types') . '</dt>';
      $output .= '<dd>' . t('The provided <em>demo Paragraph types</em> stay available even when the Paragraphs Demo module is uninstalled. They can be deleted individually on the <a href=":paragraphs">Paragraphs types page</a>.', [
        ':paragraphs' => Url::fromRoute('entity.paragraphs_type.collection')
          ->toString(),
      ]) . '</dd>';
      return $output;
      break;
  }
}

/**
 * Implements hook_preprocess_node() for paragraph node templates.
 *
 * Attach css we need for paragraph demo content.
 */
function paragraphs_demo_preprocess_node(&$variables) {

  // If more general approach is needed then implement preprocessor for
  // paragraph.html.twig.
  if ($variables['node']
    ->getType() === 'paragraphed_content_demo') {
    $variables['#attached']['library'][] = 'paragraphs_demo/drupal.paragraphs_demo';
  }
}

Functions

Namesort descending Description
paragraphs_demo_help Implements hook_help().
paragraphs_demo_preprocess_node Implements hook_preprocess_node() for paragraph node templates.