class DateFormatDeleteForm

Builds a form to delete a date format.

Hierarchy

Expanded class hierarchy of DateFormatDeleteForm

1 string reference to 'DateFormatDeleteForm'
system.routing.yml in drupal/core/modules/system/system.routing.yml
drupal/core/modules/system/system.routing.yml

File

drupal/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php, line 18
Contains \Drupal\system\Form\DateFormatDeleteForm.

Namespace

Drupal\system\Form
View source
class DateFormatDeleteForm extends ConfirmFormBase implements ControllerInterface {

  /**
   * The date format data to be deleted.
   *
   * @var array
   */
  protected $format;

  /**
   * The ID of the date format to be deleted.
   *
   * @var string
   */
  protected $formatID;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;

  /**
   * Constructs a DateFormatDeleteForm object.
   */
  public function __construct(ConfigFactory $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
    return 'system_date_delete_format_form';
  }

  /**
   * {@inheritdoc}
   */
  protected function getQuestion() {
    return t('Are you sure you want to remove the format %name : %format?', array(
      '%name' => $this->format['name'],
      '%format' => format_date(REQUEST_TIME, $this->formatID),
    ));
  }

  /**
   * {@inheritdoc}
   */
  protected function getConfirmText() {
    return t('Remove');
  }

  /**
   * {@inheritdoc}
   */
  protected function getCancelPath() {
    return 'admin/config/regional/date-time/formats';
  }

  /**
   * {@inheritdoc}
   *
   * @param string $format_id
   *   The date format ID.
   */
  public function buildForm(array $form, array &$form_state, $format_id = NULL) {

    // We don't get the format ID in the returned format array.
    $this->formatID = $format_id;
    $this->format = $this->configFactory
      ->get('system.date')
      ->get("formats.{$format_id}");
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, array &$form_state) {
    system_date_format_delete($this->formatID);
    drupal_set_message(t('Removed date format %format.', array(
      '%format' => $this->format['name'],
    )));
    $form_state['redirect'] = 'admin/config/regional/date-time/formats';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfirmFormBase::getCancelText protected function Returns a caption for the link which cancels the action. 2
ConfirmFormBase::getDescription protected function Returns additional text to display as a description. 10
ConfirmFormBase::getFormName protected function Returns the internal name used to refer to the confirmation item.
ConfirmFormBase::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm 1
DateFormatDeleteForm::$configFactory protected property The config factory.
DateFormatDeleteForm::$format protected property The date format data to be deleted.
DateFormatDeleteForm::$formatID protected property The ID of the date format to be deleted.
DateFormatDeleteForm::buildForm public function Overrides ConfirmFormBase::buildForm
DateFormatDeleteForm::create public static function Instantiates a new instance of this controller. Overrides ControllerInterface::create
DateFormatDeleteForm::getCancelPath protected function Returns the page to go to if the user cancels the action. Overrides ConfirmFormBase::getCancelPath
DateFormatDeleteForm::getConfirmText protected function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
DateFormatDeleteForm::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
DateFormatDeleteForm::getQuestion protected function Returns the question to ask the user. Overrides ConfirmFormBase::getQuestion
DateFormatDeleteForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
DateFormatDeleteForm::__construct public function Constructs a DateFormatDeleteForm object.