Commit 5f01455f authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3272637 by RenatoG: Implement the admin settings with the field to set...

Issue #3272637 by RenatoG: Implement the admin settings with the field to set the number of attributes per block
parent 552b440e
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -206,6 +206,25 @@ class BlockClassSettingsForm extends ConfigFormBase {
      '#default_value' => $config->get('enable_attributes'),
    ];

    $qty_attributes_per_block = 10;

    // If there is a settings for that use this.
    if (!empty($config->get('qty_attributes_per_block'))) {
      $qty_attributes_per_block = $config->get('qty_attributes_per_block');
    }

    // Define the settings for quantity per block.
    $form['global_settings']['attributes']['qty_attributes_per_block'] = [
      '#title' => $this->t("Quantity of attributes per block"),
      '#type' => 'number',
      '#default_value' => $qty_attributes_per_block,
      '#states' => [
        'visible' => [
          ':input[name="enable_attributes"]' => ['checked' => TRUE],
        ],
      ],
    ];

    $maxlength_attributes = FALSE;

    if (!empty($config->get('maxlength_attributes'))) {
@@ -283,6 +302,12 @@ class BlockClassSettingsForm extends ConfigFormBase {
      $form_state->setErrorByName('qty_classes_per_block', $this->t('The quantity of classes per block should be an positive value'));
    }

    $qty_attributes_per_block = $form_state->getValue('qty_attributes_per_block');

    if ($qty_attributes_per_block < 1) {
      $form_state->setErrorByName('qty_attributes_per_block', $this->t('The quantity of attributes per block should be an positive value'));
    }

    // Get the $items_per_page field.
    $items_per_page = $form_state->getValue('items_per_page');

@@ -327,6 +352,10 @@ class BlockClassSettingsForm extends ConfigFormBase {
    // Set the quantity per block in the settings.
    $config->set('qty_classes_per_block', $qty_classes_per_block);

    $qty_attributes_per_block = $form_state->getValue('qty_attributes_per_block');

    $config->set('qty_attributes_per_block', $qty_attributes_per_block);

    // Get the maxlength_block_class_field field.
    $maxlength_block_class_field = $form_state->getValue('maxlength_block_class_field');