cloudinary-8.x-1.x-dev/modules/cloudinary_media_library_widget/src/Plugin/Field/FieldFormatter/CloudinaryImageFormatter.php
modules/cloudinary_media_library_widget/src/Plugin/Field/FieldFormatter/CloudinaryImageFormatter.php
<?php
namespace Drupal\cloudinary_media_library_widget\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;
/**
* Plugin implementation of the 'cloudinary_image' formatter.
*
* This formatter is useful if you want to display an original image with
* custom applied transformation from cloudinary media library (if any).
* No image style applied, but we take into accounts breakpoints settings.
*
* @FieldFormatter(
* id = "cloudinary_image",
* label = @Translation("Cloudinary image (DEPRECATED)"),
* field_types = {
* "image",
* }
* )
*
* @deprecated in cloudinary:3.0.0 and is removed from cloudinary:4.0.0. Use
* core image field formatter.
*
* @see https://www.drupal.org/project/cloudinary/issues/3314722
*/
class CloudinaryImageFormatter extends ImageFormatter {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$element['image_style']['#access'] = FALSE;
return $element;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
foreach ($elements as &$element) {
// Fallback value.
$element['#theme'] = 'image_formatter';
}
// Invalidate cache if we update configs like default transformations.
$elements['#cache']['tags'][] = 'config:cloudinary_media_library_widget.settings';
return $elements;
}
/**
* {@inheritdoc}
*/
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return $field_definition->getTargetBundle() === 'cloudinary_image';
}
}
