Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

Code snippet that can be used to programmatically generate a title for node in Drupal 8.

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;

 * Implements hook_form_FORM_ID_alter().
function MODULE_form_node_CONTENT_TYPE_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  //Hide the title
  $form['title']['#access'] = FALSE;
function MODULE_entity_presave(EntityInterface $entity)
  if ($entity->getEntityTypeId() == 'node') {
    if ($entity->getType() == 'article') {
      $name = $entity->get('field_name')->value;
      $lastname = $entity->get('field_lastname')->value;
      $entity->set('title', $name . ' - ' . $lastname);

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts


Page Facebook