use Drupal\Core\Form\FormStateInterface;
use Drupal\metatag\MetatagManagerInterface;
use Drupal\metatag_views\MetatagViewsValuesCleanerTrait;
-use Drupal\views\ViewEntityInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
protected $viewsManager;
/**
- * Array of display settings as returned from getDisplay of ViewEntityInterface
+ * Array of display settings from ViewEntityInterface::getDisplay().
*
- * @var array
+ * @var array
*/
protected $display;
/**
- * View entity object
+ * View entity object.
*
- * @var ViewEntityInterface
+ * @var \Drupal\views\ViewEntityInterface
*/
protected $view;
+ /**
+ * {@inheritdoc}
+ */
public function __construct(MetatagManagerInterface $metatag_manager, EntityTypeManagerInterface $entity_manager) {
$this->metatagManager = $metatag_manager;
$this->viewsManager = $entity_manager->getStorage('view');
}
+ /**
+ * {@inheritdoc}
+ */
public static function create(ContainerInterface $container) {
return new static(
$container->get('metatag.manager'),
$view_id = \Drupal::request()->get('view_id');
$display_id = \Drupal::request()->get('display_id');
- // Get metatags from the view entity.
+ // Get meta tags from the view entity.
$metatags = [];
if ($view_id && $display_id) {
$metatags = metatag_get_view_tags($view_id, $display_id);
$form['metatags']['#title'] = t('Metatags');
$form['metatags']['#type'] = 'fieldset';
- // Need to create that AFTER the $form['metatags'] as the whole form
- // is passed to the $metatagManager->form() which causes duplicated field.
+ // Need to create that AFTER the $form['metatags'] as the whole form is
+ // passed to the $metatagManager->form() which causes duplicated field.
$form['view'] = [
'#type' => 'value',
'#title' => $this->t('View'),
'#required' => TRUE,
];
- $form['submit'] = array(
+ $form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Submit'),
- );
+ ];
return $form;
}
* {@inheritdoc}
*/
public function form(array $values, array $element, array $token_types = [], array $included_groups = NULL, array $included_tags = NULL) {
-
// Add the outer fieldset.
$element += [
'#type' => 'details',
unset($metatags['view']);
$metatags = $this->clearMetatagViewsDisallowedValues($metatags);
- /** @var ViewEntityInterface $view */
+ /** @var \Drupal\views\ViewEntityInterface $view */
$view = $this->viewsManager->load($view_id);
- // Store the metatags on the view.
+ // Store the meta tags on the view.
$config_name = $view->getConfigDependencyName();
$config_path = 'display.' . $display_id . '.display_options.display_extenders.metatag_display_extender.metatags';
- // Set configuration values based on form submission.
- // This always edits the original language.
+ // Set configuration values based on form submission. This always edits the
+ // original language.
$configuration = $this->configFactory()->getEditable($config_name);
if (empty($this->removeEmptyTags($metatags))) {
$configuration->clear($config_path);