You are here

entityblock.module in Entityblock 8

Enables users to turn entities in blocks.

File

entityblock.module
View source
<?php

/**
 * @file
 * Enables users to turn entities in blocks.
 */
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Entity;
use Drupal\field\Entity\FieldConfig;

/**
 * Implements template_preprocess_node().
 */
function entityblock_preprocess_node(&$variables) {
  if (!empty($variables['elements']['#entityblock'])) {
    $variables['page'] = $variables['elements']['#entityblock'];
  }
}

/**
 * Implements hook_form_FORM_ID_alter() for block_form.
 */
function entityblock_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form['settings']['provider']['#value'] == 'entityblock') {
    $form['settings']['label']['#states'] = [
      'enabled' => [
        ':input[name="settings[label_override]"]' => [
          'checked' => TRUE,
        ],
      ],
    ];

    // Remove token validator as entity block has the token and that one is validated.
    if (\Drupal::moduleHandler()
      ->moduleExists('token')) {
      $delta = array_search('token_element_validate', $form['settings']['label']['#element_validate']);
      unset($form['settings']['label']['#element_validate'][$delta]);
    }
  }
}

/**
 * Implements hook_module_implements_alter().
 */
function entityblock_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'form_alter' && isset($implementations['entityblock'])) {
    $group = $implementations['entityblock'];
    unset($implementations['entityblock']);
    $implementations['entityblock'] = $group;
  }
}