You are here

field_image_style.module in Field Image Style 8

File

field_image_style.module
View source
<?php

/**
 * @file
 * Contains field_image_style.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;

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

    // Main module help for the field_image_style module.
    case 'help.page.field_image_style':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Defines a field type for images styles. This field value can be use by any image formatter.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_form_FORM_ID_alter() for 'field_storage_config_edit_form'.
 */
function field_image_style_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state) {
  if ($form_state
    ->getFormObject()
    ->getEntity()
    ->getType() == 'image_style') {

    // We only support setting one image style at the time so it doesn't make sense
    // to let the site builder choose anything else.
    $form['cardinality_container']['cardinality']['#default_value'] = 1;
    $form['cardinality_container']['#access'] = FALSE;
  }
}

/**
 * Implements hook_field_widget_info_alter().
 */
function field_image_style_field_widget_info_alter(array &$info) {

  // Add the image_style field type to options_select & options_buttons widgets
  $info['options_select']['field_types'][] = 'image_style';
  $info['options_buttons']['field_types'][] = 'image_style';
}

/**
 * Implements hook_field_formatter_info_alter().
 */
function field_image_style_field_formatter_info_alter(array &$info) {

  // Add the image_style field type to list_default & list_key formatters
  $info['list_default']['field_types'][] = 'image_style';
  $info['list_key']['field_types'][] = 'image_style';
}