public function CheeseburgerMenuService::buildRowFromEntity in Cheeseburger Menu 5.0.x
Builds sortable entity row for cheeseburger config form.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity to build.
array $default_value: Cheeseburger config for entity.
Return value
array Sortable entity row.
1 call to CheeseburgerMenuService::buildRowFromEntity()
- CheeseburgerMenuService::getMenusAsRows in src/
CheeseburgerMenuService.php - Returns sortable menu rows for cheeseburger config form.
File
- src/
CheeseburgerMenuService.php, line 126
Class
- CheeseburgerMenuService
- Base service providing functions.
Namespace
Drupal\cheeseburger_menuCode
public function buildRowFromEntity(EntityInterface $entity, array $default_value = []) {
$row = [];
$row['label'] = [
'#markup' => $entity
->label(),
];
// Override default values to markup elements.
$row['#attributes']['class'][] = 'draggable';
$row['#weight'] = $default_value['weight'] ?? 100;
// Add weight column.
$row['weight'] = [
'#type' => 'weight',
'#title' => $this
->t('Weight for @title', [
'@title' => $entity
->label(),
]),
'#title_display' => 'invisible',
'#default_value' => $default_value['weight'] ?? 100,
'#attributes' => [
'class' => [
'weight',
],
],
];
$row['weight']['#delta'] = 100;
$row['menu_type'] = [
'#type' => 'item',
'#markup' => $entity
->getEntityType()
->getLabel(),
'#value' => $entity
->getEntityTypeId(),
];
$row['settings'] = [
'#type' => 'details',
'#title' => $this
->t('Settings'),
'#tree' => TRUE,
];
$settings_form =& $row['settings'];
$settings = $default_value['settings'] ?? [];
$settings_form['show_links_in_navigation'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show links in navigation(only first level)'),
'#default_value' => $settings['show_links_in_navigation'] ?? 0,
];
$settings_form['max_depth'] = [
'#type' => 'number',
'#title' => $this
->t('Maximum menu depth. Use 0 for no limit.'),
'#default_value' => $settings['max_depth'] ?? 0,
'#states' => [
'visible' => [
'input[name="settings[menus][' . $entity
->id() . '][settings][show_links_in_navigation]"]' => [
'checked' => FALSE,
],
],
],
];
$settings_form['initial_visibility_level'] = [
'#type' => 'number',
'#title' => $this
->t('Initial visibility level'),
'#default_value' => $settings['initial_visibility_level'] ?? 1,
'#access' => $entity
->getEntityTypeId() !== 'taxonomy_vocabulary',
];
$settings_form['default_expanded'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Expanded by default (menu items)'),
'#default_value' => $settings['default_expanded'] ?? FALSE,
'#states' => [
'visible' => [
'input[name="settings[menus][' . $entity
->id() . '][settings][show_links_in_navigation]"]' => [
'checked' => FALSE,
],
],
],
];
$settings_form['show_title_in_navigation'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show title in navigation'),
'#default_value' => $settings['show_title_in_navigation'] ?? 1,
];
$settings_form['show_title_above_menu'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show title above menu'),
'#default_value' => $settings['show_title_above_menu'] ?? 1,
];
$settings_form['collapsible_title'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Make title collapsible'),
'#default_value' => $settings['collapsible_title'] ?? 0,
'#states' => [
'visible' => [
'input[name="settings[menus][' . $entity
->id() . '][settings][show_title_above_menu]"]' => [
'checked' => TRUE,
],
],
],
];
$settings_form['title_default_expanded'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Title expanded by default'),
'#default_value' => $settings['title_default_expanded'] ?? 1,
'#states' => [
'visible' => [
'input[name="settings[menus][' . $entity
->id() . '][settings][show_title_above_menu]"]' => [
'checked' => TRUE,
],
'input[name="settings[menus][' . $entity
->id() . '][settings][collapsible_title]"]' => [
'checked' => TRUE,
],
],
],
];
$settings_form['override_title'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use overriden title'),
'#default_value' => $settings['override_title'] ?? 0,
];
$settings_form['title_override'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title override'),
'#states' => [
'visible' => [
'input[name="settings[menus][' . $entity
->id() . '][settings][override_title]"]' => [
'checked' => TRUE,
],
],
],
'#size' => 20,
'#default_value' => $settings['title_override'] ?? NULL,
];
$settings_form['icon'] = [
'#type' => 'managed_file',
'#title' => $this
->t('Menu icon'),
'#upload_validators' => [
'file_validate_extensions' => [
'svg',
],
],
'#description' => isset($settings['icon']) && !empty($settings['icon']) ? $this
->t('Icon is uploaded, you can overwrite it') : NULL,
];
$row['#menu_id'] = $entity
->id();
return $row;
}