You are here

merci_line_item.module in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

File

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

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

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

    // Main module help for the merci_line_item module.
    case 'help.page.merci_line_item':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 */
function merci_line_item_theme() {
  $theme = [];
  $theme['merci_line_item'] = array(
    'render element' => 'elements',
    'file' => 'merci_line_item.page.inc',
    'template' => 'merci_line_item',
  );
  $theme['merci_line_item_content_add_list'] = [
    'render element' => 'content',
    'variables' => [
      'content' => NULL,
    ],
    'file' => 'merci_line_item.page.inc',
  ];
  return $theme;
}

/**
* Implements hook_theme_suggestions_HOOK().
*/
function merci_line_item_theme_suggestions_merci_line_item(array $variables) {
  $suggestions = array();
  $entity = $variables['elements']['#merci_line_item'];
  $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
  $suggestions[] = 'merci_line_item__' . $sanitized_view_mode;
  $suggestions[] = 'merci_line_item__' . $entity
    ->bundle();
  $suggestions[] = 'merci_line_item__' . $entity
    ->bundle() . '__' . $sanitized_view_mode;
  $suggestions[] = 'merci_line_item__' . $entity
    ->id();
  $suggestions[] = 'merci_line_item__' . $entity
    ->id() . '__' . $sanitized_view_mode;
  return $suggestions;
}

/**
 * Implements hook_field_widget_form_alter().
 */
function merci_line_item_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) {

  // Add a css class to widget form elements for all fields of type mytype.
  $field_definition = $context['items']
    ->getFieldDefinition();
  if ($field_definition
    ->getType() == 'entity_reference') {

    // Be sure not to overwrite existing attributes.
    $element['#attributes']['class'][] = 'myclass';
  }
}

/**
 * Implements hook_field_widget_third_party_settings_form().
 */
function merci_line_item_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $element = [];

  // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field
  // widgets.
  if ($plugin
    ->getPluginId() == 'inline_entity_form_complex') {
    $element['merci_line_item_setting'] = [
      '#type' => 'checkbox',
      '#title' => t('Merci Line Item'),
      '#default_value' => $plugin
        ->getThirdPartySetting('merci_line_item', 'merci_line_item_setting'),
    ];
  }
  return $element;
}