You are here

function entity_hierarchy_form_node_type_form_builder in Entity Reference Hierarchy 8

Entity form builder for the node type form to save the hierarchy settings using the configuration factory.

1 string reference to 'entity_hierarchy_form_node_type_form_builder'
entity_hierarchy_form_node_type_form_alter in ./entity_hierarchy.module
Implements Here we are altering the node type edit form to include hierarchy settings, such as setting which content types should support one or more child content types.

File

./entity_hierarchy.module, line 147
A module to make nodes hierarchical.

Code

function entity_hierarchy_form_node_type_form_builder($entity_type, NodeTypeInterface $type, &$form, FormStateInterface $form_state) {
  $node_type = $type
    ->get('type');
  $config = \Drupal::getContainer()
    ->get('config.factory')
    ->getEditable('entity_hierarchy.settings');
  $config
    ->set('nh_allowchild_' . $node_type, $form_state
    ->getValue('nh_allowchild'));

  //  $config->set('nh_createmenu_'.$node_type, $form_state->getValue('nh_createmenu'));
  //  $config->set('nh_multiple_'.$node_type, $form_state->getValue('nh_multiple'));
  $config
    ->set('nh_defaultparent_' . $node_type, $form_state
    ->getValue('nh_defaultparent'));
  $config
    ->save();
}