Commit 3d8195bd authored by John Herreño's avatar John Herreño Committed by Damien McKenna
Browse files

Issue #3102602 by jedihe, Gnanagowthaman sankar, thalles, DamienMcKenna,...

Issue #3102602 by jedihe, Gnanagowthaman sankar, thalles, DamienMcKenna, Berdir: Use DI to add services to the settings form.
parent 2c35c2b2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ Metatag 8.x-1.x-dev, xxxx-xx-xx
#3102582 by DamienMcKenna, dbourrion: Change uses of http:// to https://.
#3101532 by DamienMcKenna, heddn, slv_: Only attach Metatag migration field
  logic on 'Drupal 7' migrations, e.g. core upgrades.
#3102602 by jedihe, Gnanagowthaman sankar, thalles, DamienMcKenna, Berdir: Use
  DI to add services to the settings form.


Metatag 8.x-1.11, 2019-12-20
+40 −6
Original line number Diff line number Diff line
@@ -2,14 +2,50 @@

namespace Drupal\metatag\Form;

use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\metatag\MetatagManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines the configuration export form.
 */
class MetatagSettingsForm extends ConfigFormBase {

  /**
   * The metatag.manager service.
   *
   * @var \Drupal\metatag\MetatagManagerInterface
   */
  protected $metatagManager;

  /**
   * The entity_type.bundle.info service.
   *
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
   */
  protected $entityTypeBundleInfo;

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->entityTypeBundleInfo = $container->get('entity_type.bundle.info');
    $instance->metatagManager = $container->get('metatag.manager');
    $instance->state = $container->get('state');

    return $instance;
  }

  /**
   * {@inheritdoc}
   */
@@ -28,8 +64,8 @@ class MetatagSettingsForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    if (\Drupal::state()->get('system.maintenance_mode')) {
      \Drupal::messenger()->addMessage($this->t('Please note that while the site is in maintenance mode none of the usual meta tags will be output.'));
    if ($this->state->get('system.maintenance_mode')) {
      $this->messenger()->addMessage($this->t('Please note that while the site is in maintenance mode none of the usual meta tags will be output.'));
    }
    $settings = $this->config('metatag.settings')->get('entity_type_groups');

@@ -41,12 +77,10 @@ class MetatagSettingsForm extends ConfigFormBase {
      '#tree' => TRUE,
    ];

    $metatag_manager = \Drupal::service('metatag.manager');
    $bundle_manager = \Drupal::service('entity_type.bundle.info');
    $metatag_groups = $metatag_manager->sortedGroups();
    $metatag_groups = $this->metatagManager->sortedGroups();
    $entity_types = MetatagDefaultsForm::getSupportedEntityTypes();
    foreach ($entity_types as $entity_type => $entity_label) {
      $bundles = $bundle_manager->getBundleInfo($entity_type);
      $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type);
      foreach ($bundles as $bundle_id => $bundle_info) {
        // Create an option list for each bundle.
        $options = [];