public function MenuSyncForm::buildForm in Structure Sync 8
Same name and namespace in other branches
- 2.x src/Form/MenuSyncForm.php \Drupal\structure_sync\Form\MenuSyncForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ MenuSyncForm.php, line 61
Class
- MenuSyncForm
- Import and export form for content in structure, like taxonomy terms.
Namespace
Drupal\structure_sync\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$helper = new StructureSyncHelper();
$form['title'] = [
'#type' => 'page_title',
'#title' => $this
->t('Menu links'),
];
$form['export'] = [
'#type' => 'details',
'#title' => $this
->t('Export'),
'#weight' => 1,
'#open' => TRUE,
];
$form['export']['export_menu_links'] = [
'#type' => 'submit',
'#value' => $this
->t('Export menu links'),
'#name' => 'exportMenuLinks',
'#button_type' => 'primary',
'#submit' => [
[
$helper,
'exportMenuLinks',
],
],
];
$menuList = [];
$entities = StructureSyncHelper::getEntityManager()
->getStorage('menu_link_content')
->loadMultiple();
foreach ($entities as $entity) {
$menuId = $entity->menu_name
->getValue()[0]['value'];
$menuName = $this
->config('system.menu.' . $menuId)
->get('label');
$menuList[$menuId] = $menuName;
}
$form['export']['export_menu_list'] = [
'#type' => 'checkboxes',
'#options' => $menuList,
'#default_value' => array_keys($menuList),
'#title' => $this
->t('Select the menus you would like to export'),
];
$form['import'] = [
'#type' => 'details',
'#title' => $this
->t('Import'),
'#weight' => 2,
'#open' => TRUE,
];
$menus = $this
->config('structure_sync.data')
->get('menus');
if (empty($menus)) {
$form['import']['import_no_data'] = [
'#type' => 'markup',
'#markup' => $this
->t("There's no data to import, please do an export first."),
];
return $form;
}
$form['import']['import_menus_safe'] = [
'#type' => 'submit',
'#value' => $this
->t('Import menu links (safely)'),
'#name' => 'importMenusSafe',
'#button_type' => 'primary',
'#submit' => [
[
$helper,
'importMenuLinksSafe',
],
],
];
$form['import']['import_menus_full'] = [
'#type' => 'submit',
'#value' => $this
->t('Import menu links (full)'),
'#name' => 'importMenusFull',
'#submit' => [
[
$helper,
'importMenuLinksFull',
],
],
];
$form['import']['import_menus_force'] = [
'#type' => 'submit',
'#value' => $this
->t('Import menu links (force)'),
'#name' => 'importMenusForce',
'#submit' => [
[
$helper,
'importMenuLinksForce',
],
],
];
$menu_list = [];
foreach ($menus as $menu) {
$menuName = $this
->config('system.menu.' . $menu['menu_name'])
->get('label');
$menu_list[$menu['menu_name']] = $menuName;
}
$form['import']['import_menu_list'] = [
'#type' => 'checkboxes',
'#options' => $menu_list,
'#default_value' => array_keys($menu_list),
'#title' => $this
->t('Select the menus you would like to import'),
];
return $form;
}