You are here

markup.module in Markup 8

Same filename and directory in other branches
  1. 6 markup.module
  2. 7 markup.module

Defines a field type for displaying markup on the node/edit form.

File

markup.module
View source
<?php

/**
 * @file
 * Defines a field type for displaying markup on the node/edit form.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Remove 'number of values' selection.
 */
function markup_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state) {

  /** @var \Drupal\field_ui\Form\FieldStorageConfigEditForm $form_object */
  $form_object = $form_state
    ->getFormObject();

  /** @var \Drupal\field\Entity\FieldStorageConfig $entity */
  $entity = $form_object
    ->getEntity();
  if ($entity
    ->get('module') == 'markup') {
    unset($form['cardinality_container']);
  }
}

/**
 * Implements hook_help().
 */
function markup_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name === 'help.page.markup') {
    $readme_file = file_exists(__DIR__ . '/README.md') ? __DIR__ . '/README.md' : __DIR__ . '/README.txt';
    if (!file_exists($readme_file)) {
      return NULL;
    }
    $text = file_get_contents($readme_file);
    if ($text && !\Drupal::moduleHandler()
      ->moduleExists('markdown')) {
      return '<pre>' . $text . '</pre>';
    }
    else {

      // Use the Markdown filter to render the README.
      $filter_manager = \Drupal::service('plugin.manager.filter');
      $settings = \Drupal::configFactory()
        ->get('markdown.settings')
        ->getRawData();
      $config = [
        'settings' => $settings,
      ];
      $filter = $filter_manager
        ->createInstance('markdown', $config);
      return $filter
        ->process($text, 'en');
    }
  }
  return NULL;
}