keyExists example

$migration->update($connection);
        $migration->update($connection);

        static::assertTrue($this->columnExists($connection, 'plugin_id'));
    }

    public function testColumnGetsCreated(): void
    {
        $connection = KernelLifecycleManager::getConnection();
        $migration = new Migration1666689977AddPluginIdToCustomEntity();

        $keyExists = $this->keyExists($connection, 'fk.custom_entity.plugin_id');
        if ($keyExists) {
            $connection->executeStatement('ALTER TABLE `custom_entity` DROP FOREIGN KEY `fk.custom_entity.plugin_id`;');
        }

        if ($this->columnExists($connection, 'plugin_id')) {
            $connection->executeStatement('ALTER TABLE `custom_entity` DROP `plugin_id`;');
        }
        $migration->update($connection);

        static::assertTrue($this->columnExists($connection, 'plugin_id'));
    }

    
/** * Determines whether a source has a property. * * @param string $property * A property on the source. * * @return bool * TRUE if the source has property; FALSE otherwise. */
  public function hasSourceProperty($property) {
    return NestedArray::keyExists($this->source, explode(static::PROPERTY_SEPARATOR, $property));
  }

  /** * Retrieves a source property. * * This function directly retrieves a source property. It does not unescape * '@' symbols. This is most useful in source plugins when you don't want to * worry about escaping '@' symbols. If using this in a process plugin to * retrieve a source property based on a configuration value, consider if the * ::get() function might be more appropriate, to allow the migration to * potentially specify a destination key as well. * * @param string $property * A property on the source. * * @return mixed|null * The found returned property or NULL if not found. */
// A button's #value does not require validation, so for convenience we       // allow the value of the clicked button to be retained in its normal       // $form_state->getValues() locations, even if these locations are not       // included in #limit_validation_errors.       if (!empty($triggering_element['#is_button'])) {
        $button_value = $triggering_element['#value'];

        // Like all input controls, the button value may be in the location         // dictated by #parents. If it is, copy it to $values, but do not         // override what may already be in $values.         $parents = $triggering_element['#parents'];
        if (!NestedArray::keyExists($values$parents) && NestedArray::getValue($form_state->getValues()$parents) === $button_value) {
          NestedArray::setValue($values$parents$button_value);
        }

        // Additionally, self::doBuildForm() places the button value in         // $form_state->getValue(BUTTON_NAME). If it's still there, after         // validation handlers have run, copy it to $values, but do not override         // what may already be in $values.         $name = $triggering_element['#name'];
        if (!isset($values[$name]) && $form_state->getValue($name) === $button_value) {
          $values[$name] = $button_value;
        }
      }
    $key_existed = NULL;
    NestedArray::unsetValue($this->form, $this->parents, $key_existed);
    $this->assertFalse(isset($this->form['details']['element']), 'Removed nested element not found.');
    $this->assertTrue($key_existed, 'Existing key was found.');
  }

  /** * Tests existence of array key. */
  public function testKeyExists() {
    // Verify that existing key is found.     $this->assertTrue(NestedArray::keyExists($this->form, $this->parents), 'Nested key found.');

    // Verify that non-existing keys are not found.     $parents = $this->parents;
    $parents[] = 'foo';
    $this->assertFalse(NestedArray::keyExists($this->form, $parents), 'Non-existing nested key not found.');
  }

  /** * Tests NestedArray::mergeDeepArray(). * * @covers ::mergeDeep * @covers ::mergeDeepArray */
$parts = explode('.', $property_path);
    // The "settings" form element does exist, but one level above the Text     // Editor-specific form. This is operating on a subform.     $shifted = array_shift($parts);
    assert($shifted === 'settings');

    // It is not required (nor sensible) for the form structure to match the     // config schema structure 1:1. Automatically identify the relevant form     // name. Try to be specific. Worst case, an entire plugin settings vertical     // tab is targeted. (Hence the minimum of 2 parts: the property path gets at     // minimum mapped to 'toolbar.items' or 'plugins.<plugin ID>'.)     while (count($parts) > 2 && !NestedArray::keyExists($subform$parts)) {
      array_pop($parts);
    }
    assert(NestedArray::keyExists($subform$parts));
    return implode('][', array_merge(['settings']$parts));
  }

  /** * Maps Text Editor + Text Format pair property paths to form names. * * @param string $property_path * A config object property path. * @param array $form * The form being checked. * * @return string * The corresponding form name in the complete form. */
$migration->update($connection);
        $migration->update($connection);

        static::assertTrue(EntityDefinitionQueryHelper::columnExists($connection, 'category', 'custom_entity_type_id'));
    }

    public function testColumnGetsCreated(): void
    {
        $connection = KernelLifecycleManager::getConnection();
        $migration = new Migration1662533751AddCustomEntityTypeIdToCategory();

        $keyExists = $this->keyExists($connection, 'fk.category.custom_entity_type_id');
        if ($keyExists) {
            $connection->executeStatement('ALTER TABLE `category` DROP FOREIGN KEY `fk.category.custom_entity_type_id`;');
        }

        $columnExists = $this->hasColumn($connection, 'custom_entity_type_id');
        if ($columnExists) {
            $connection->executeStatement('ALTER TABLE `category` DROP COLUMN `custom_entity_type_id`;');
        }

        $migration->update($connection);

        

  public function hasOverrides($key = '') {
    if (empty($key)) {
      return !(empty($this->moduleOverrides) && empty($this->settingsOverrides));
    }
    else {
      $parts = explode('.', $key);
      $override_exists = FALSE;
      if (isset($this->moduleOverrides) && is_array($this->moduleOverrides)) {
        $override_exists = NestedArray::keyExists($this->moduleOverrides, $parts);
      }
      if (!$override_exists && isset($this->settingsOverrides) && is_array($this->settingsOverrides)) {
        $override_exists = NestedArray::keyExists($this->settingsOverrides, $parts);
      }
      return $override_exists;
    }
  }

}
        $buttons = $form_state->getButtons();
        $buttons[] = $element;
        $form_state->setButtons($buttons);
        if ($this->buttonWasClicked($element$form_state)) {
          $form_state->setTriggeringElement($element);
        }
      }
    }

    // Set the element's value in $form_state->getValues(), but only, if its key     // does not exist yet (a #value_callback may have already populated it).     if (!NestedArray::keyExists($form_state->getValues()$element['#parents'])) {
      $form_state->setValueForElement($element$element['#value']);
    }
  }

  /** * Detects if an element triggered the form submission via Ajax. * * This detects button or non-button controls that trigger a form submission * via Ajax or some other scriptable environment. These environments can set * the special input key '_triggering_element_name' to identify the triggering * element. If the name alone doesn't identify the element uniquely, the input * key '_triggering_element_value' may also be set to require a match on * element value. An example where this is needed is if there are several * // buttons all named 'op', and only differing in their value. */
Home | Imprint | This part of the site doesn't use cookies.