function entity_hierarchy_form_node_type_form_alter in Entity Reference Hierarchy 8
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.
See also
HierarchyManagerInterface::hierarchyGetNodeTypeSettingsForm
File
- ./
entity_hierarchy.module, line 122 - A module to make nodes hierarchical.
Code
function entity_hierarchy_form_node_type_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var \Drupal\entity_hierarchy\HierarchyManager $hierarchy_manager */
$hierarchy_manager = \Drupal::service('entity_hierarchy.manager');
// TODO: check if there's any reason we're not including the base $form
// declaration in the class method.
$type = $form['type']['#default_value'];
// The content type
$form['hierarchy'] = array(
'#type' => 'details',
'#group' => 'additional_settings',
'#title' => t('Entity Hierarchy'),
'#weight' => 10,
);
// Right now, we add this js to all admin pages using hook_page_attachments; see below.
// $form['#attached']['library'][] = entity_hierarchy/entity_hierarchy.nodetypeform;
$form['hierarchy'] += $hierarchy_manager
->hierarchyGetNodeTypeSettingsForm($type);
$form['#entity_builders'][] = 'entity_hierarchy_form_node_type_form_builder';
}