iframe_consent-1.0.x-dev/src/Form/IframeConsentDomainForm.php

src/Form/IframeConsentDomainForm.php
<?php

declare(strict_types=1);

namespace Drupal\iframe_consent\Form;

use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Form controller for the domains entity edit forms.
 */
final class IframeConsentDomainForm extends ContentEntityForm {


  /**
   * The iframe consent settings service.
   *
   * @var \Drupal\iframe_consent\Service\IframeConsentHelper
   */
  protected $iframeConsentHelper;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->iframeConsentHelper = $container->get('iframe_consent.helper');
    return $instance;
  }

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state): int {
    $result = parent::save($form, $form_state);

    $message_args = ['%label' => $this->entity->toLink()->toString()];
    $logger_args = [
      '%label' => $this->entity->label(),
      'link' => $this->entity->toLink($this->t('View'))->toString(),
    ];

    switch ($result) {
      case SAVED_NEW:
        $this->messenger()->addStatus($this->t('New domains %label has been created.', $message_args));
        $this->logger('iframe_consent')->notice('New domains %label has been created.', $logger_args);
        break;

      case SAVED_UPDATED:
        $this->messenger()->addStatus($this->t('The domains %label has been updated.', $message_args));
        $this->logger('iframe_consent')->notice('The domains %label has been updated.', $logger_args);
        break;

      default:
        throw new \LogicException('Could not save the entity.');
    }

    $form_state->setRedirectUrl($this->entity->toUrl('collection'));

    // Clear the cache tags.
    $this->iframeConsentHelper->clearCacheTags();

    return $result;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc