diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php index c14ab91..59206aa 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php @@ -8,6 +8,11 @@ namespace Drupal\image\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Utility\LinkGeneratorInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'image' formatter. @@ -20,7 +25,66 @@ * } * ) */ -class ImageFormatter extends ImageFormatterBase { +class ImageFormatter extends ImageFormatterBase implements ContainerFactoryPluginInterface { + + /** + * The current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** + * The link generator. + * + * @var \Drupal\Core\Utility\LinkGeneratorInterface + */ + protected $linkGenerator; + + /** + * Constructs an ImageFormatter object. + * + * @param string $plugin_id + * The plugin_id for the formatter. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * The definition of the field to which the formatter is associated. + * @param array $settings + * The formatter settings. + * @param string $label + * The formatter label display setting. + * @param string $view_mode + * The view mode. + * @param array $third_party_settings + * Any third party settings settings. + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. + * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator + * The link generator service. + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, LinkGeneratorInterface $link_generator) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); + $this->currentUser = $current_user; + $this->linkGenerator = $link_generator; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('current_user'), + $container->get('link_generator') + ); + } /** * {@inheritdoc} @@ -45,6 +109,11 @@ public function settingsForm(array $form, array &$form_state) { '#options' => $image_styles, ); + $element['configure_styles'] = array( + '#markup' => $this->linkGenerator->generate($this->t('Configure Image Styles'), 'image.style_list'), + '#access' => $this->currentUser->hasPermission('administer image styles'), + ); + $link_types = array( 'content' => t('Content'), 'file' => t('File'),