Commit cdbdc4d4 authored by alexpott's avatar alexpott

Issue #2534074 by Dom., manishmore, poornima.n: Update error messages in field...

Issue #2534074 by Dom., manishmore, poornima.n: Update error messages in field formatter when no Responsive Image Style available
parent 7461ba21
......@@ -16,6 +16,8 @@
use Drupal\Core\Url;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Utility\LinkGeneratorInterface;
/**
* Plugin for responsive image formatter.
......@@ -42,6 +44,20 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa
*/
protected $imageStyleStorage;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The link generator.
*
* @var \Drupal\Core\Utility\LinkGeneratorInterface
*/
protected $linkGenerator;
/**
* Constructs a ResponsiveImageFormatter object.
*
......@@ -63,12 +79,18 @@ class ResponsiveImageFormatter extends ImageFormatterBase implements ContainerFa
* The responsive image style storage.
* @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage
* The image style storage.
* @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
* The link generator service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityStorageInterface $responsive_image_style_storage, EntityStorageInterface $image_style_storage) {
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityStorageInterface $responsive_image_style_storage, EntityStorageInterface $image_style_storage, LinkGeneratorInterface $link_generator, AccountInterface $current_user) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->responsiveImageStyleStorage = $responsive_image_style_storage;
$this->imageStyleStorage = $image_style_storage;
$this->linkGenerator = $link_generator;
$this->currentUser = $current_user;
}
/**
......@@ -84,7 +106,9 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration['view_mode'],
$configuration['third_party_settings'],
$container->get('entity.manager')->getStorage('responsive_image_style'),
$container->get('entity.manager')->getStorage('image_style')
$container->get('entity.manager')->getStorage('image_style'),
$container->get('link_generator'),
$container->get('current_user')
);
}
......@@ -118,6 +142,10 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
'#default_value' => $this->getSetting('responsive_image_style'),
'#required' => TRUE,
'#options' => $responsive_image_options,
'#description' => array(
'#markup' => $this->linkGenerator->generate($this->t('Configure Responsive Image Styles'), new Url('entity.responsive_image_style.collection')),
'#access' => $this->currentUser->hasPermission('administer responsive image styles'),
),
);
$link_types = array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment