Commit c4cdd9b3 authored by Michelle Cox's avatar Michelle Cox Committed by Damien McKenna
Browse files

Issue #2844696 by DamienMcKenna, Michelle: Allow the field to control whether...

Issue #2844696 by DamienMcKenna, Michelle: Allow the field to control whether it is displayed in the sidebar or not.
parent 771ab7f5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ By DamienMcKenna: Minor code readability tweak.
  data.
#3112784 by thalles: Missing doc comment into Create method to $instance
  metatag\Form\MetatagSettingsForm.
#2844696 by DamienMcKenna, Michelle: Allow the field to control whether it is
  displayed in the sidebar or not.


Metatag 8.x-1.11, 2019-12-20
+8 −0
Original line number Diff line number Diff line
@@ -6,3 +6,11 @@ field.value.metatag:
    value:
      type: string
      label: 'Metatags'

field.widget.settings.metatag_firehose:
  type: mapping
  label: 'Advanced meta tags form'
  mapping:
    sidebar:
      type: boolean
      label: 'Place field in sidebar'
+50 −3
Original line number Diff line number Diff line
@@ -62,6 +62,43 @@ class MetatagFirehose extends WidgetBase implements ContainerFactoryPluginInterf
    );
  }

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    return [
      'sidebar' => TRUE,
    ] + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element['sidebar'] = [
      '#type' => 'checkbox',
      '#title' => t('Place field in sidebar'),
      '#default_value' => $this->getSetting('sidebar'),
      '#description' => t('If checked, the field will be placed in the sidebar on entity forms.'),
    ];

    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    if ($this->getSetting('sidebar')) {
      $summary[] = t('Use sidebar: Yes');
    }
    else {
      $summary[] = t('Use sidebar: No');
    }

    return $summary;
  }

  /**
   * {@inheritdoc}
   */
@@ -103,18 +140,28 @@ class MetatagFirehose extends WidgetBase implements ContainerFactoryPluginInterf
    $entity_bundle = $item->getEntity()->bundle();

    // See if there are requested groups for this entity type and bundle.
    $groups = !empty($entity_type_groups[$entity_type]) && !empty($entity_type_groups[$entity_type][$entity_bundle]) ? $entity_type_groups[$entity_type][$entity_bundle] : [];
    $groups = [];
    if (!empty($entity_type_groups[$entity_type]) && !empty($entity_type_groups[$entity_type][$entity_bundle])) {
      $groups = $entity_type_groups[$entity_type][$entity_bundle];
    }

    // Limit the form to requested groups, if any.
    if (!empty($groups)) {
      $element = $this->metatagManager->form($values, $element, [$entity_type], $groups);
    }

    // Otherwise, display all groups.
    else {
      $element = $this->metatagManager->form($values, $element, [$entity_type]);
    }

    // Put the form element into the form's "advanced" group.
    // If the "sidebar" option was checked on the field widget, put the
    // form element into the form's "advanced" group. Otherwise, let it
    // default to the main field area.
    $sidebar = $this->getSetting('sidebar');
    if ($sidebar) {
      $element['#group'] = 'advanced';
    }

    return $element;
  }