2015-08-17 17:00:26 -07:00
< ? php
/**
* @ file
* Administration functions for language . module .
*/
use Drupal\Core\Render\Element ;
use Drupal\Core\Template\Attribute ;
/**
* Prepares variables for language negotiation configuration form .
*
* Default template : language - content - configuration - form . html . twig .
*
* @ param array $variables
* An associative array containing :
* - form : A render element representing the form .
*/
function template_preprocess_language_negotiation_configure_form ( & $variables ) {
$form =& $variables [ 'form' ];
2017-04-13 15:53:35 +01:00
$variables [ 'language_types' ] = [];
2015-08-17 17:00:26 -07:00
foreach ( $form [ '#language_types' ] as $type ) {
2017-04-13 15:53:35 +01:00
$header = [
2015-08-17 17:00:26 -07:00
t ( 'Detection method' ),
t ( 'Description' ),
t ( 'Enabled' ),
t ( 'Weight' ),
2017-04-13 15:53:35 +01:00
];
2015-08-17 17:00:26 -07:00
// If there is at least one operation enabled show the operation column.
if ( $form [ $type ][ '#show_operations' ]) {
$header [] = t ( 'Operations' );
}
2017-04-13 15:53:35 +01:00
$table = [
2015-08-17 17:00:26 -07:00
'#type' => 'table' ,
'#header' => $header ,
2017-04-13 15:53:35 +01:00
'#attributes' => [ 'id' => 'language-negotiation-methods-' . $type ],
'#tabledrag' => [
[
2015-08-17 17:00:26 -07:00
'action' => 'order' ,
'relationship' => 'sibling' ,
'group' => 'language-method-weight-' . $type ,
2017-04-13 15:53:35 +01:00
],
],
];
2015-08-17 17:00:26 -07:00
foreach ( $form [ $type ][ 'title' ] as $id => $element ) {
// Do not take form control structures.
if ( is_array ( $element ) && Element :: child ( $id )) {
$table [ $id ][ '#attributes' ][ 'class' ][] = 'draggable' ;
$table [ $id ][ '#weight' ] = $element [ '#weight' ];
2017-04-13 15:53:35 +01:00
$table [ $id ][ 'title' ] = [
2015-08-17 17:00:26 -07:00
'#prefix' => '<strong>' ,
$form [ $type ][ 'title' ][ $id ],
'#suffix' => '</strong>' ,
2017-04-13 15:53:35 +01:00
];
2015-08-17 17:00:26 -07:00
$table [ $id ][ 'description' ] = $form [ $type ][ 'description' ][ $id ];
$table [ $id ][ 'enabled' ] = $form [ $type ][ 'enabled' ][ $id ];
$table [ $id ][ 'weight' ] = $form [ $type ][ 'weight' ][ $id ];
if ( $form [ $type ][ '#show_operations' ]) {
$table [ $id ][ 'operation' ] = $form [ $type ][ 'operation' ][ $id ];
}
// Unset to prevent rendering along with children.
unset ( $form [ $type ][ 'title' ][ $id ]);
unset ( $form [ $type ][ 'description' ][ $id ]);
unset ( $form [ $type ][ 'enabled' ][ $id ]);
unset ( $form [ $type ][ 'weight' ][ $id ]);
unset ( $form [ $type ][ 'operation' ][ $id ]);
}
}
// Unset configurable to prevent rendering twice with children.
$configurable = isset ( $form [ $type ][ 'configurable' ]) ? $form [ $type ][ 'configurable' ] : NULL ;
unset ( $form [ $type ][ 'configurable' ]);
2017-04-13 15:53:35 +01:00
$variables [ 'language_types' ][] = [
2015-08-17 17:00:26 -07:00
'type' => $type ,
'title' => $form [ $type ][ '#title' ],
'description' => $form [ $type ][ '#description' ],
'configurable' => $configurable ,
'table' => $table ,
'children' => $form [ $type ],
'attributes' => new Attribute (),
2017-04-13 15:53:35 +01:00
];
2015-08-17 17:00:26 -07:00
// Prevent the type from rendering with the remaining form child elements.
unset ( $form [ $type ]);
}
$variables [ 'children' ] = $form ;
}
/**
2015-11-04 11:11:27 -08:00
* Prepares variables for language content settings table templates .
*
* Default template : language - content - settings - table . html . twig .
*
* @ param array $variables
* An associative array containing :
* - element : An associative array containing the properties of the element .
* Properties used : #bundle_label, #title.
2015-08-17 17:00:26 -07:00
*/
function template_preprocess_language_content_settings_table ( & $variables ) {
// Add a render element representing the bundle language settings table.
$element = $variables [ 'element' ];
2017-04-13 15:53:35 +01:00
$header = [
[
2015-08-17 17:00:26 -07:00
'data' => $element [ '#bundle_label' ],
2017-04-13 15:53:35 +01:00
'class' => [ 'bundle' ],
],
[
2015-08-17 17:00:26 -07:00
'data' => t ( 'Configuration' ),
2017-04-13 15:53:35 +01:00
'class' => [ 'operations' ],
],
];
2015-08-17 17:00:26 -07:00
2017-04-13 15:53:35 +01:00
$rows = [];
2015-08-17 17:00:26 -07:00
foreach ( Element :: children ( $element ) as $bundle ) {
2017-04-13 15:53:35 +01:00
$rows [ $bundle ] = [
'data' => [
[
'data' => [
2015-08-17 17:00:26 -07:00
'#prefix' => '<label>' ,
'#suffix' => '</label>' ,
2015-09-04 13:20:09 -07:00
'#plain_text' => $element [ $bundle ][ 'settings' ][ '#label' ],
2017-04-13 15:53:35 +01:00
],
'class' => [ 'bundle' ],
],
[
2015-08-17 17:00:26 -07:00
'data' => $element [ $bundle ][ 'settings' ],
2017-04-13 15:53:35 +01:00
'class' => [ 'operations' ],
],
],
'class' => [ 'bundle-settings' ],
];
2015-08-17 17:00:26 -07:00
}
2015-11-04 11:11:27 -08:00
$variables [ 'title' ] = $element [ '#title' ];
2017-04-13 15:53:35 +01:00
$variables [ 'build' ] = [
2015-08-17 17:00:26 -07:00
'#header' => $header ,
'#rows' => $rows ,
'#type' => 'table' ,
2017-04-13 15:53:35 +01:00
];
2015-08-17 17:00:26 -07:00
}