You are here

paragraphs_collection.module in Paragraphs Collection 8

File

paragraphs_collection.module
View source
<?php

/**
 * @file
 * Contains paragraphs_collection.module
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\paragraphs_collection\Plugin\paragraphs\Behavior\ParagraphsLanguagePlugin;
use Drupal\paragraphs_collection\Plugin\paragraphs\Behavior\ParagraphsLockablePlugin;
use Drupal\paragraphs_collection\Plugin\paragraphs\Behavior\ParagraphsStylePlugin;

/**
 * Implements hook_ENTITY_TYPE_access().
 */
function paragraphs_collection_paragraph_access(ParagraphInterface $paragraph, $operation, AccountInterface $account) {
  $access_result = ParagraphsLockablePlugin::determineParagraphAccess($paragraph, $operation, $account);
  return $access_result
    ->andIf(ParagraphsLanguagePlugin::determineParagraphAccess($paragraph, $operation, $account));
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function paragraphs_collection_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
  $paragraph = $variables['elements']['#paragraph'];
  if ($paragraph
    ->getParagraphType()
    ->hasEnabledBehaviorPlugin('style')) {
    if ($templates = $paragraph
      ->getParagraphType()
      ->getBehaviorPlugin('style')
      ->getStyleTemplates($paragraph)) {
      foreach ($templates as $template) {
        $suggestions[] = 'paragraph__' . $paragraph
          ->bundle() . '__' . $template;
      }
      return $suggestions;
    }
  }
}

/**
 * Implements hook_theme().
 */
function paragraphs_collection_theme() {
  return [
    'paragraph__separator' => array(
      'base hook' => 'paragraph',
    ),
    'paragraph__quote' => array(
      'base hook' => 'paragraph',
    ),
    'field__paragraphs_title' => [
      'base hook' => 'field',
    ],
    'field__paragraphs_subtitle' => [
      'base hook' => 'field',
    ],
    'field__paragraphs_intro' => [
      'base hook' => 'field',
    ],
    'field__paragraphs_text' => [
      'base hook' => 'field',
    ],
    'field__paragraphs_footer' => [
      'base hook' => 'field',
    ],
    'field__paragraphs_quote_text' => [
      'base hook' => 'field',
    ],
    'field__paragraphs_quote_author' => [
      'base hook' => 'field',
    ],
  ];
}

/**
 * * Implements hook_modules_installed().
 */
function paragraphs_collection_modules_installed($modules) {
  \Drupal::service('paragraphs_collection.style_discovery')
    ->reset();
  \Drupal::cache('discovery')
    ->deleteMultiple([
    'paragraphs_collection_grid_layouts',
  ]);
}

/**
 * * Implements hook_themes_installed().
 */
function paragraphs_collection_themes_installed($themes) {
  \Drupal::service('paragraphs_collection.style_discovery')
    ->reset();
  \Drupal::cache('discovery')
    ->deleteMultiple([
    'paragraphs_collection_grid_layouts',
  ]);
}

/**
 * * Implements hook_themes_uninstalled().
 */
function paragraphs_collection_themes_uninstalled($themes) {
  \Drupal::service('paragraphs_collection.style_discovery')
    ->reset();
  \Drupal::cache('discovery')
    ->deleteMultiple([
    'paragraphs_collection_grid_layouts',
  ]);
}