use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\EntityForm;
-use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
-use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\StringTranslation\TranslatableMarkup;
+use Drupal\metatag\MetatagManager;
/**
* Class MetatagDefaultsForm.
$form['#ajax_wrapper_id'] = 'metatag-defaults-form-ajax-wrapper';
$ajax = [
'wrapper' => $form['#ajax_wrapper_id'],
- 'callback' => '::rebuildForm'
+ 'callback' => '::rebuildForm',
];
$form['#prefix'] = '<div id="' . $form['#ajax_wrapper_id'] . '">';
$form['#suffix'] = '</div>';
'#options' => $options,
'#required' => TRUE,
'#default_value' => $default_type,
- '#ajax' => $ajax + ['trigger_as' => ['name' => 'select_id_submit']]
+ '#ajax' => $ajax + [
+ 'trigger_as' => [
+ 'name' => 'select_id_submit',
+ ],
+ ],
];
$form['select_id_submit'] = [
'#type' => 'submit',
'#name' => 'select_id_submit',
'#ajax' => $ajax,
'#attributes' => [
- 'class' => ['js-hide']
- ]
+ 'class' => ['js-hide'],
+ ],
];
$values = [];
}
return $form;
}
+ /**
+ * {@inheritdoc}
+ */
+ protected function actions(array $form, FormStateInterface $form_state) {
+ $actions = parent::actions($form, $form_state);
+ if (isset($actions['delete'])) {
+ $actions['delete']['#access'] = $actions['delete']['#access'] && !in_array($this->entity->id(), MetatagManager::protectedDefaults());
+ }
+ return $actions;
+ }
+
/**
* {@inheritdoc}
*/
$tag_values = [];
foreach ($tags as $tag_id => $tag_definition) {
if ($form_state->hasValue($tag_id)) {
- // Some plugins need to process form input before storing it.
- // Hence, we set it and then get it.
+ // Some plugins need to process form input before storing it. Hence, we
+ // set it and then get it.
$tag = $tag_manager->createInstance($tag_id);
$tag->setValue($form_state->getValue($tag_id));
if (!empty($tag->value())) {
'%label' => $metatag_defaults->label(),
]));
break;
+
default:
drupal_set_message($this->t('Saved the %label Metatag defaults.', [
'%label' => $metatag_defaults->label(),
protected function getAvailableBundles() {
$options = [];
$entity_types = $this->getSupportedEntityTypes();
- /** @var EntityTypeManagerInterface $entity_manager */
+ /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
$entity_manager = \Drupal::service('entity_type.manager');
- /** @var EntityTypeBundleInfoInterface $bundle_info */
+ /** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info */
$bundle_info = \Drupal::service('entity_type.bundle.info');
$metatags_defaults_manager = $entity_manager->getStorage('metatag_defaults');
foreach ($entity_types as $entity_type => $entity_label) {
* Returns a list of supported entity types.
*
* @return array
- * A list of available entity types as $machine_name => $label.
+ * A list of available entity types as $machine_name => $label.
*/
protected function getSupportedEntityTypes() {
$entity_types = [];
- /** @var EntityTypeManagerInterface $entity_manager */
+ /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
$entity_manager = \Drupal::service('entity_type.manager');
// A list of entity types that are not supported.
return $entity_types;
}
- /**
- * Returns the text label for the entity type specified.
- *
- * @param EntityTypeInterface $entityType
- *
- * @return string
- */
- protected function getEntityTypeLabel(EntityTypeInterface $entityType) {
- $label = $entityType->getLabel();
-
- if (is_a($label, 'Drupal\Core\StringTranslation\TranslatableMarkup')) {
- /** @var TranslatableMarkup $label */
- $label = $label->render();
- }
-
- return $label;
- }
+ /**
+ * Returns the text label for the entity type specified.
+ *
+ * @param Drupal\Core\Entity\EntityTypeInterface $entityType
+ * The entity type to process.
+ *
+ * @return string
+ * A label.
+ */
+ protected function getEntityTypeLabel(EntityTypeInterface $entityType) {
+ $label = $entityType->getLabel();
+
+ if (is_a($label, 'Drupal\Core\StringTranslation\TranslatableMarkup')) {
+ /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
+ $label = $label->render();
+ }
+
+ return $label;
+ }
}