cloudinary-8.x-1.x-dev/modules/cloudinary_media_library_widget/src/Plugin/Field/FieldType/CloudinaryImage.php

modules/cloudinary_media_library_widget/src/Plugin/Field/FieldType/CloudinaryImage.php
<?php

namespace Drupal\cloudinary_media_library_widget\Plugin\Field\FieldType;

use Drupal\Core\Form\FormStateInterface;
use Drupal\image\Plugin\Field\FieldType\ImageItem;

/**
 * Plugin implementation of the 'cloudinary_image' field type.
 *
 * @FieldType(
 *   id = "cloudinary_image",
 *   label = @Translation("Cloudinary image"),
 *   description = @Translation("This field stores a cloudinary asset info and the ID of the file as an integer value."),
 *   category = @Translation("Media"),
 *   default_widget = "cloudinary_widget",
 *   default_formatter = "image",
 *   no_ui = TRUE,
 *   column_groups = {
 *     "file" = {
 *       "label" = @Translation("File"),
 *       "columns" = {
 *         "target_id", "width", "height", "transformation"
 *       },
 *       "require_all_groups_for_translation" = TRUE
 *     },
 *     "alt" = {
 *       "label" = @Translation("Alt"),
 *       "translatable" = TRUE
 *     },
 *     "title" = {
 *       "label" = @Translation("Title"),
 *       "translatable" = TRUE
 *     },
 *   },
 *   list_class = "\Drupal\file\Plugin\Field\FieldType\FileFieldItemList",
 *   constraints = {"ReferenceAccess" = {}, "FileValidation" = {}}
 * )
 */
class CloudinaryImage extends ImageItem {

  use CloudinaryFileTrait {
    fieldSettingsForm as baseFieldSettingsForm;
    storageSettingsForm as baseStorageSettingsForm;
  }

  /**
   * {@inheritdoc}
   */
  public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
    $element = $this->baseStorageSettingsForm($form, $form_state, $has_data);

    // @TODO: Rewrite default_image logic to use cloudinary widget.
    $element['default_image']['#access'] = FALSE;

    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $element = $this->baseFieldSettingsForm($form, $form_state);

    // Hide options that have no sense as we do not upload an image to
    // cloudinary server.
    $element['max_resolution']['#access'] = FALSE;
    $element['min_resolution']['#access'] = FALSE;
    // @TODO: Rewrite default_image logic to use cloudinary widget.
    $element['default_image']['#access'] = FALSE;

    return $element;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc