Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds_content / dds_content.module
Size: Mime:
<?php

/**
 * Implements hook_theme().
 */
function dds_content_theme($existing, $type, $theme, $path) {
  return [
    'dds_button' => [
      'variables' => [
        'title' => NULL,
        'url_title' => NULL,
        'url' => NULL,
        'target_blank' => FALSE,
        'button_style' => '',
      ],
    ],
    'dds_link_with_target' => [
      'variables' => [
        'title' => NULL,
        'url_title' => NULL,
        'url' => NULL,
        'target_blank' => FALSE,
      ],
    ],
    'page_header' => [
      'variables' => [
        'page' => NULL,
      ],
    ],
  ];

}

/**
 * Implements hook_locale_translation_projects_alter().
 */
function dds_content_locale_translation_projects_alter(&$projects) {
  $module_handler = \Drupal::service('module_handler');
  $path = $module_handler->getModule('dds_content')->getPath();
  $projects['dds_content']['info']['interface translation server pattern']
    = $path . '/translations/%language.po';
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function dds_content_menu_local_tasks_alter(&$data) {
  //disable cloning of special pages
  if (is_array($data) && isset($data['tabs']) && isset($data['tabs'][0])) {
    if (isset($data['tabs'][0]['entity_clone.clone:node.clone_tab'])) {
      $node = \Drupal::routeMatch()->getParameter('node');
      if ($node && $node->getType() == 'special_page') {
        unset($data['tabs'][0]['entity_clone.clone:node.clone_tab']);
      }
    }
    if (isset($data['tabs'][0]['views_view:view.scheduler_scheduled_content.user_page'])) {
      unset($data['tabs'][0]['views_view:view.scheduler_scheduled_content.user_page']);
    }
  }
}

/**
 * Implements hook_form_alter().
 */
function dds_content_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  switch ($form_id) {
    case 'entity_clone_form':
      $form['description'] = [
        '#markup' => '<p>'
          . t('Pressing the clone button takes a copy of the current page.')
          . '</p>',
      ];
      _removeAllExceptParagraphsCloneForm($form);
      break;
    case 'node_basic_page_edit_form':
    case 'node_special_page_edit_form':
      $form['#attached']['library'][] = 'dds_content/node_edit_protection';
      break;
  }
  //hack to fix weird allowed_editors behavior
  if (preg_match('/^node_.*(_edit)?_form$/', $form_id)) {
    if (isset($form['field_header_subline'])
      && isset($form['field_header_subline']['widget'][0]['#format'])
    ) {
      $form['field_header_subline']['widget'][0]['#format'] = 'header_html';
    }
  }
}

function _removeAllExceptParagraphsCloneForm(&$form) {
  foreach ($form['recursive'] as $key => $recursive) {
    if (is_array($recursive)) {
      foreach ($recursive['references'] as $ref_key => $references) {
        $form['recursive'][$key]['#attributes'] = ['class' => ['hidden']];
        if (!empty($references['children'])) {
          if (isset($references['target_entity_type_id']) && $references['target_entity_type_id']['#value'] != 'paragraph') {
            continue;
          }
          $form['recursive'][$key]['references'][$ref_key]['clone']["#default_value"]
            = TRUE;
          _removeAllExceptParagraphsCloneForm($form['recursive'][$key]['references'][$ref_key]['children']);
        }
      }
    }
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function dds_content_theme_suggestions_page_header_alter(array &$suggestions, array $variables) {
  /** @var \Drupal\node\Entity\Node $node */
  $node = $variables['page']['node'];
  if ($node->hasField('field_header_collapsed')
    && (bool) $node->get('field_header_collapsed')->value === TRUE
  ) {
    $suggestions[] = $variables['theme_hook_original'] . '__collapsed';
  }
}