Drupal 8 Add Entity Display Field

[Solved] Drupal 8 Add Entity Display Field | Php - Code Explorer | yomemimo.com
Question : drupal 8 add entity display field

Answered by : gleaming-gannet-htlwomz3dthc

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\node\NodeInterface;
/** * Implements hook_entity_extra_field_info(). */
function MY_MODULE_entity_extra_field_info() { $extra = []; $extra['node']['news']['display']['field_thank_you'] = [ 'label' => t('Thank You'), 'description' => t('Thank You pseudo field.'), 'weight' => 0, 'visible' => TRUE, ]; return $extra;
}
/** * Implements hook_ENTITY_TYPE_view(). */
function MY_MODULE_node_view(array &$build, NodeInterface $node, EntityViewDisplayInterface $display, $view_mode) { if ($display->getComponent('field_thank_you')) { $thank_you_notice = \Drupal::config('MY_MODULE.settings')->get('thank_you_notice'); $build['field_thank_you'] = [ '#type' => 'markup', '#markup' => $thank_you_notice, ]; }
}

Source : | Last Update : Thu, 25 Aug 22

Answers related to drupal 8 add entity display field

Code Explorer Popular Question For Php