Skip to main content

Drupal 8 and hook form alter: How to check if taxonomy term is new or old?

If you want to check with hook_form_alter if the taxonomy term is new or updated (old) you can't use the form_id or the $form_state->getFormObject()->getOperation() because it always returns "default". The solution for this is :

$form_state->getFormObject()->getEntity()->isNew() 
//So for example: 
$form_state->getFormObject()->getEntity()->isNew() ? do_this($form,$form_state) : do_that($form,$form_state); 

 

hook_form_alter taxonomy vocabulary

Latest Articles

Using drupal/core-composer-scaffold to prevent rewriting .htaccess or robots.txt file admin_pixelthi… Sun, 12/01/2024 - 16:49 Using drupal/core-composer-scaffold to prevent rewriting .htaccess or robots.txt file

Using drupal/core-composer-scaffold to prevent rewriting .htaccess or robots.txt file

composer
Controlling ckeditor styling options with hook_editor_js_settings_alter admin_pixelthi… Thu, 05/16/2024 - 10:49 Controlling ckeditor styling options with hook_editor_js_settings_alter

Controlling ckeditor styling options with hook_editor_js_settings_alter

php hook hook_editor_js_settings_alter hook_field_widget_single_[WIDGET_TYPE]_form_alter
Upgrading Drupal 9 Modules for Drupal 10: A Simple Guide admin_pixelthi… Tue, 09/05/2023 - 14:18 Upgrading Drupal 9 Modules for Drupal 10: A Simple Guide

Upgrading Drupal 9 Modules for Drupal 10: A Simple Guide

composer drupal9 drupal10