diff --git a/node_form_api_fields.api.php b/node_form_api_fields.api.php index 376f828..ebb8e93 100644 --- a/node_form_api_fields.api.php +++ b/node_form_api_fields.api.php @@ -35,13 +35,13 @@ */ function hook_node_form_api_fields_form_alter(&$form, $defaults, $context) { - $form['form_api_fields'] = array( + $form['form_api_fields'] = [ '#type' => 'textfield', '#title' => t('Extra Field'), '#size' => 60, '#maxlength' => 128, '#required' => TRUE, - ); + ]; } diff --git a/node_form_api_fields.module b/node_form_api_fields.module index c2a9fbc..e51e210 100644 --- a/node_form_api_fields.module +++ b/node_form_api_fields.module @@ -47,21 +47,21 @@ function node_form_api_fields_form_node_page_edit_form_alter(&$form, FormStateIn * Modify the node create and edit form for page bundle. */ function _node_form_api_fields_form_node_page_form_alter(&$form, FormStateInterface $form_state, $form_id) { - $defaults = array(); + $defaults = []; $node = $form_state->getFormObject()->getEntity(); if (isset($node->form_api_fields)) { $defaults = $node->form_api_fields; } // Run the alter to allow modules to add fields to this form. - $form_api_fields = array(); - $context = array( + $form_api_fields = []; + $context = [ 'form' => $form, 'form_state' => $form_state, 'form_id' => $form_id, 'node' => $node, 'nid' => $node->id(), - ); + ]; \Drupal::moduleHandler()->alter('node_form_api_fields_form', $form_api_fields, $defaults, $context); // If we have any extra fields to add. @@ -75,14 +75,14 @@ function _node_form_api_fields_form_node_page_form_alter(&$form, FormStateInterf $weight = $config->get('fieldset_default_weight'); // Add our extra fields fieldset. - $form['form_api_fields'] = array( + $form['form_api_fields'] = [ '#type' => 'fieldset', '#title' => (!is_null($label) ? $label : 'Additional Fields'), '#weight' => ($weight ? $weight : 50), - ); + ]; } else { - $form['form_api_fields'] = array(); + $form['form_api_fields'] = []; } // Set defaults if not set. @@ -96,7 +96,7 @@ function _node_form_api_fields_form_node_page_form_alter(&$form, FormStateInterf $form['form_api_fields'] += $form_api_fields; // Add out submit handler. - $skip_actions = array('delete', 'preview', '#type'); + $skip_actions = ['delete', 'preview', '#type']; foreach ($form['actions'] as $action => $settings) { if (!in_array($action, $skip_actions)) { $form['actions'][$action]['#submit'][] = 'node_form_api_fields_node_page_form_submit'; diff --git a/src/NodeFormApiFieldsSettingsForm.php b/src/NodeFormApiFieldsSettingsForm.php index 04e697e..d7a7f7b 100644 --- a/src/NodeFormApiFieldsSettingsForm.php +++ b/src/NodeFormApiFieldsSettingsForm.php @@ -32,28 +32,28 @@ class NodeFormApiFieldsSettingsForm extends ConfigFormBase { public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('node_form_api_fields.settings'); - $form['wrap_in_fieldset'] = array( + $form['wrap_in_fieldset'] = [ '#type' => 'checkbox', '#title' => $this->t('Wrap in Fieldset'), '#default_value' => $config->get('wrap_in_fieldset'), '#description' => $this->t('Check this box to wrap all fields created using the hook_node_form_api_fields_form_alter() in a fieldset.'), - ); + ]; - $form['fieldset_wrapper_label'] = array( + $form['fieldset_wrapper_label'] = [ '#type' => 'textfield', '#title' => $this->t('Fieldset Wrapper Label'), '#default_value' => $config->get('fieldset_wrapper_label'), '#description' => $this->t('Set the text in the legend of the wrapper fieldset to something other than the default "Additional Fields".'), - '#states' => array( - 'visible' => array( - ':input[name="wrap_in_fieldset"]' => array('checked' => TRUE), - ), - ), - ); + '#states' => [ + 'visible' => [ + ':input[name="wrap_in_fieldset"]' => ['checked' => TRUE], + ], + ], + ]; - $form['fieldset_default_weight'] = array( + $form['fieldset_default_weight'] = [ '#type' => 'textfield', '#title' => $this->t('Fieldset Default Weight'), '#default_value' => $config->get('fieldset_default_weight'), @@ -61,12 +61,12 @@ class NodeFormApiFieldsSettingsForm extends ConfigFormBase { '#description' => $this->t('Set the default weight for the fieldset to set its initial position in the form. You could override this on a specific form by changing the $form[\'extra_fields\'][\'#weight\']'), - '#states' => array( - 'visible' => array( - ':input[name="wrap_in_fieldset"]' => array('checked' => TRUE), - ), - ), - ); + '#states' => [ + 'visible' => [ + ':input[name="wrap_in_fieldset"]' => ['checked' => TRUE], + ], + ], + ]; return parent::buildForm($form, $form_state); }