By admin , 24 April, 2023 Debug twig with PHPStorm or VSCode using twig_tweak module Just add {{ drupal_breakpoint() }} and enable debug in PHPStorm or VSCode Tags twig phpstorm vscode
By admin , 22 April, 2023 Create form and update markup field after form submit /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['actions'] = [ '#type' => 'actions', ]; if ($markup = $form_state->get( Tags form
By admin , 22 April, 2023 Add suggestion to webform block $webform_name = $variables['elements']['#configuration']['webform_id']; if ($webform_name) { $suggestions[] = 'block__webform__' . $webform_name; } Tags webform suggestions
By admin , 22 April, 2023 Add class to HTML tag /** * Implements hook_preprocess_HOOK(). */ function hram_preprocess_html(&$variables) { $variables['html_attributes']->addClass('h-100'); } Tags preprocess
By admin , 22 April, 2023 Get entity from form object /** @var \Drupal\Core\Entity\EntityForm $form_object */ $form_object = $form_state->getFormObject(); if ($form_object instanceof EntityForm) { $entity = $form_object->getEntity(); // Do something with the entity. } Tags form
By admin , 22 April, 2023 Add twig template to custom entity /** * Implements hook_theme(). */ function mymodule_theme() { return [ 'my_entity' => [ 'render element' => 'elements', ], ]; } * Implements hook_preprocess_HOOK(). */ Tags twig custom entity
By admin , 1 April, 2023 Inject States to FormBase use Drupal\Core\State\StateInterface; /** * The state store. * * @var \Drupal\Core\State\StateInterface */ protected $state; /** * Drush command constructor. * * @param \Drupal\Core\State\StateInterface $state * T Tags states dependency injection
By admin , 1 April, 2023 Save custom data to States Reading StateA single value.$val = \Drupal::state()->get('key');Multiple key/value pairs.$pairs = \Drupal::state()->getMultiple($keys);Writing StateA single value.\Drupal::state()->set('key','value');Multiple values. Tags states
By admin , 1 April, 2023 Make custom entity translatable Add to file src/Entity/MyEntity.php/** * Defines the my entity class. * * @ContentEntityType( ... * data_table = "my_entity_field_data", * translatable = TRUE, ... * entity_keys = { ... * "langcode" = "langcode" * }, ... * ) */Add ->setTranslatable(TRUE) to baseFieldDefinitions. For example Tags translate custom entity
By admin , 31 March, 2023 Get the current language programmatically Get Language ID$language = \Drupal::languageManager()->getCurrentLanguage()->getId();Get Language name$language = \Drupal::languageManager()->getCurrentLanguage()->getName(); Tags translate