function Helper::isContentForm

Same name and namespace in other branches
  1. main core/themes/admin/src/Helper.php \Drupal\admin\Helper::isContentForm()

Check if we´re on a content edit form.

Parameters

\Drupal\Core\Form\FormStateInterface|null $form_state: The current state of the form.

string $form_id: The form id.

5 calls to Helper::isContentForm()
FormHooks::stickyActionButtonsAndSidebar in core/themes/admin/src/Hook/FormHooks.php
Add some major form overrides.
PreprocessHooks::html in core/themes/admin/src/Hook/PreprocessHooks.php
Implements hook_preprocess_HOOK() for HTML.
PreprocessHooks::preprocessDescriptionToggle in core/themes/admin/src/Hook/PreprocessHooks.php
Generic preprocess enabling toggle.
ThemeHooks::textFormat in core/themes/admin/src/Hook/ThemeHooks.php
Prerender callback for text_format elements.
ThemeSuggestionHooks::page in core/themes/admin/src/Hook/ThemeSuggestionHooks.php
Implements hook_theme_suggestions_HOOK_alter() for page.

File

core/themes/admin/src/Helper.php, line 266

Class

Helper
Admin helper methods.

Namespace

Drupal\admin

Code

public static function isContentForm(?FormStateInterface $form_state = NULL, string $form_id = '') : bool {
  static $is_content_form;
  if ($is_content_form) {
    return TRUE;
  }
  if ($form_id) {
    // Forms to exclude.
    // If media library widget, don't use new content edit form.
    // gin_preprocess_html is not triggered here, so checking the form id is
    // enough.
    $form_ids_to_ignore = [
      'media_library_add_form_',
      'views_form_media_library_widget_',
      'views_exposed_form',
    ];
    $form_ids_to_ignore = array_merge(\Drupal::moduleHandler()->invokeAll('admin_content_form_ignore_form_ids'), $form_ids_to_ignore);
    foreach ($form_ids_to_ignore as $form_id_to_ignore) {
      if (str_contains($form_id, $form_id_to_ignore)) {
        return FALSE;
      }
    }
  }
  if ($form_state && (($form_state->getBuildInfo()['base_form_id'] ?? NULL) === 'node_form' || $form_state->getFormObject() instanceof ContentEntityFormInterface)) {
    $is_content_form = TRUE;
    return TRUE;
  }
  static $is_content_form_route;
  if (!isset($is_content_form_route)) {
    // Get route name.
    $route_name = \Drupal::routeMatch()->getRouteName();
    // Routes to include.
    $route_names = [
      'node.add',
      'block_content.add_page',
      'block_content.add_form',
      'entity.block_content.canonical',
      'entity.media.add_form',
      'entity.media.canonical',
      'entity.media.edit_form',
      'entity.node.content_translation_add',
      'entity.node.content_translation_edit',
      'entity.node.edit_form',
      'entity.menu.add_link_form',
      'menu_ui.link_edit',
    ];
    // API check.
    $additional_routes = \Drupal::moduleHandler()->invokeAll('admin_content_form_routes');
    $route_names = array_merge($additional_routes, $route_names);
    \Drupal::moduleHandler()->alter('admin_content_form_routes', $route_names);
    \Drupal::service('theme.manager')->alter('admin_content_form_routes', $route_names);
    $is_content_form_route = in_array($route_name, $route_names, TRUE);
  }
  return $is_content_form_route;
}

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