Commit a1e766f7 authored by renatog's avatar renatog Committed by renatog
Browse files

Issue #3273420 by RenatoG: Implement the autocomplete on attribute keys. Store the key on preSave

parent 6919737e
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -154,6 +154,8 @@ class BlockClassHelperService {
    // Get the block class.
    $block_classes = $entity->getThirdPartySetting('block_class', 'classes');

    $attributes = $entity->getThirdPartySetting('block_class', 'attributes');

    switch ($default_case) {

      case 'uppercase':
@@ -205,6 +207,49 @@ class BlockClassHelperService {
    // Save.
    $config->save();

    // Get the keys stored.
    $attribute_keys_stored = $config->get('attribute_keys_stored');

    // Decode this to get an array with those values.
    $attribute_keys_stored = Json::decode($attribute_keys_stored);

    // Verify if it's empty and set a default array on this.
    if (empty($attribute_keys_stored)) {
      $attribute_keys_stored = [];
    }

    // Get the array with the values.
    $current_attributes = explode(PHP_EOL, $attributes);

    // Do a foreach to get all items.
    foreach ($current_attributes as $current_attribute) {

      // Get by pipe to be able to get the key value.
      $attribute_array = explode('|', $current_attribute);

      // Get the attribute key.
      $attribute_key = $attribute_array[0];

      // Put that on array.
      $attribute_keys_stored[] = $attribute_key;

    }

    // Combine to use the id and value.
    $attribute_keys_stored = array_combine($attribute_keys_stored, $attribute_keys_stored);

    // Merge the values.
    $attribute_keys_stored = array_merge($attribute_keys_stored, $attribute_keys_stored);

    // Encode that to store in JSON.
    $attribute_keys_stored = Json::encode($attribute_keys_stored);

    // Set in the object.
    $config->set('attribute_keys_stored', $attribute_keys_stored);

    // Save  it.
    $config->save();

  }

  /**