public function viewElements(FieldItemListInterface $items, $langcode) { $entity = $items->getEntity(); $elements = array(); foreach ($items as $delta => $item) { $value = $item->getValue(); // Replace the tokens with their respective values. $data = array(); foreach(unserialize($value['value']) as $key => $key_value) { $data[$key] = \Drupal::token()->replace($key_value, [$entity->getEntityTypeId() => $entity]); $data[$key] = preg_replace ('/<[^>]*>/', '', $data[$key]); } $elements[$delta] = [ '#theme' => 'raw_formatter', '#raw_value' => json_encode($data), ]; } return $elements; }
How to set the page title in Drupal 8? drupal_set_title() in Drupal 8 ? drupal_get_title() in Drupal8?
Using the following lines of code in hook_form_alter() , able to set the title and get the title after saving the code do CLEAR CACHE drupal_set_title() in Drupal8 $request = \ Drupal :: request (); if ( $route = $request -> attributes -> get (\ Symfony \ Cmf \ Component \ Routing \ RouteObjectInterface :: ROUTE_OBJECT )) { $route -> setDefault ( '_title' , 'New Title' ); } drupal_get_title() in Drupal8 $request = \ Drupal :: request (); if ( $route = $request -> attributes -> get (\ Symfony \ Cmf \ Component \ Routing \ RouteObjectInterface :: ROUTE_OBJECT )) { $title = \ Drupal :: service ( 'title_resolver' ) -> getTitle ( $request , $route ); }
Comments
Post a Comment