Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
< ? php
/**
* @ file
* Provides hook implementations for Field Layout .
*/
use Drupal\Core\Entity\ContentEntityFormInterface ;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface ;
use Drupal\Core\Entity\EntityInterface ;
use Drupal\Core\Form\FormStateInterface ;
use Drupal\Core\Routing\RouteMatchInterface ;
use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface ;
use Drupal\field_layout\Entity\FieldLayoutEntityFormDisplay ;
use Drupal\field_layout\Entity\FieldLayoutEntityViewDisplay ;
use Drupal\field_layout\FieldLayoutBuilder ;
use Drupal\field_layout\Form\FieldLayoutEntityFormDisplayEditForm ;
use Drupal\field_layout\Form\FieldLayoutEntityViewDisplayEditForm ;
/**
* Implements hook_help () .
*/
function field_layout_help ( $route_name , RouteMatchInterface $route_match ) {
switch ( $route_name ) {
case 'help.page.field_layout' :
$output = '<h3>' . t ( 'About' ) . '</h3>' ;
$output .= '<p>' . t ( 'The Field Layout module allows you to arrange fields into regions on forms and displays of entities such as nodes and users.' ) . '</p>' ;
$output .= '<p>' . t ( 'For more information, see the <a href=":field-layout-documentation">online documentation for the Field Layout module</a>.' , [ ':field-layout-documentation' => 'https://www.drupal.org/documentation/modules/field_layout' ]) . '</p>' ;
return $output ;
}
}
/**
* Implements hook_entity_type_alter () .
*/
function field_layout_entity_type_alter ( array & $entity_types ) {
2021-05-20 20:47:18 +00:00
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
$entity_types [ 'entity_view_display' ] -> setClass ( FieldLayoutEntityViewDisplay :: class );
$entity_types [ 'entity_form_display' ] -> setClass ( FieldLayoutEntityFormDisplay :: class );
// The form classes are only needed when Field UI is installed.
if ( \Drupal :: moduleHandler () -> moduleExists ( 'field_ui' )) {
$entity_types [ 'entity_view_display' ] -> setFormClass ( 'edit' , FieldLayoutEntityViewDisplayEditForm :: class );
$entity_types [ 'entity_form_display' ] -> setFormClass ( 'edit' , FieldLayoutEntityFormDisplayEditForm :: class );
}
}
/**
* Implements hook_entity_view_alter () .
*/
function field_layout_entity_view_alter ( array & $build , EntityInterface $entity , EntityViewDisplayInterface $display ) {
if ( $display instanceof EntityDisplayWithLayoutInterface ) {
2018-03-20 11:47:25 +00:00
\Drupal :: classResolver ( FieldLayoutBuilder :: class ) -> buildView ( $build , $display );
Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
}
}
/**
* Implements hook_form_alter () .
*/
function field_layout_form_alter ( & $form , FormStateInterface $form_state , $form_id ) {
$form_object = $form_state -> getFormObject ();
if ( $form_object instanceof ContentEntityFormInterface && $display = $form_object -> getFormDisplay ( $form_state )) {
if ( $display instanceof EntityDisplayWithLayoutInterface ) {
2018-03-20 11:47:25 +00:00
\Drupal :: classResolver ( FieldLayoutBuilder :: class ) -> buildForm ( $form , $display );
Issue #2796173 by tim.plunkett, samuel.mortenson, xjm, jibran, effulgentsia, dawehner, swentel, tedbow, phenaproxima, larowlan, yoroy, dsnopek, tacituseu, japerry, webchick, amateescu, aspilicious: Add experimental Field Layout module to allow entity view/form modes to switch between layouts
2017-01-26 01:55:44 +00:00
}
}
}