class NodeFormHooks

Form hook implementations for the node module.

Hierarchy

Expanded class hierarchy of NodeFormHooks

File

core/modules/node/src/Hook/NodeFormHooks.php, line 16

Namespace

Drupal\node\Hook
View source
class NodeFormHooks {
  use StringTranslationTrait;
  public function __construct(protected readonly ConfigFactoryInterface $configFactory) {
  }
  
  /**
   * Implements hook_form_FORM_ID_alter().
   *
   * Alters the theme form to use the admin theme on node editing.
   *
   * @see self::systemThemesAdminFormSubmit()
   */
  public function formSystemThemesAdminFormAlter(&$form, FormStateInterface $form_state, $form_id) : void {
    $form['admin_theme']['use_admin_theme'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Use the administration theme when editing or creating content'),
      '#description' => $this->t('Control which roles can "View the administration theme" on the <a href=":permissions">Permissions page</a>.', [
        ':permissions' => Url::fromRoute('user.admin_permissions.module', [
          'modules' => 'system',
        ])->toString(),
      ]),
      '#default_value' => $this->configFactory
        ->getEditable('node.settings')
        ->get('use_admin_theme'),
    ];
    $form['#submit'][] = [
      self::class,
      'systemThemesAdminFormSubmit',
    ];
  }
  
  /**
   * Form submission handler for system_themes_admin_form().
   *
   * @see self::formSystemThemesAdminFormAlter
   */
  public static function systemThemesAdminFormSubmit($form, FormStateInterface $form_state) : void {
    \Drupal::configFactory()->getEditable('node.settings')
      ->set('use_admin_theme', $form_state->getValue('use_admin_theme'))
      ->save();
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
NodeFormHooks::formSystemThemesAdminFormAlter public function Implements hook_form_FORM_ID_alter().
NodeFormHooks::systemThemesAdminFormSubmit public static function Form submission handler for system_themes_admin_form().
NodeFormHooks::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.