/**
  * Update entity browser configuration.
  *
  * @param string $browser
  *   Id of the entity browser.
  * @param array $configuration
  *   Configuration array to update.
  * @param array $oldConfiguration
  *   Only if current config is same like old config we are updating.
  *
  * @return bool
  *   Indicates if config was updated or not.
  */
 public function updateEntityBrowserConfig($browser, $configuration, $oldConfiguration = [])
 {
     $ebConfig = $this->configFactory->getEditable('entity_browser.browser.' . $browser);
     $config = $ebConfig->get();
     if (!empty($oldConfiguration) && DiffArray::diffAssocRecursive($oldConfiguration, $config)) {
         return FALSE;
     }
     $ebConfig->setData(NestedArray::mergeDeep($config, $configuration));
     $ebConfig->save();
     // Update entity browser edit form.
     $entityBrowserConfig = $this->tempStoreFactory->get('entity_browser.config');
     $storage = $entityBrowserConfig->get($browser);
     if (!empty($storage)) {
         foreach ($configuration as $key => $value) {
             $part = $storage['entity_browser']->getPluginCollections()[$key];
             $part->setConfiguration(NestedArray::mergeDeep($part->getConfiguration(), $value));
         }
         $entityBrowserConfig->set($browser, $storage);
     }
     return TRUE;
 }
Ejemplo n.º 2
0
 /**
  * Tests DiffArray::diffAssocRecursive().
  */
 public function testDiffAssocRecursive()
 {
     $expected = array('different' => 'no', 'int_diff' => 1, 'array_diff' => array('same' => 'same'), 'array_compared_to_string' => array('value'), 'string_compared_to_array' => 'value', 'new' => 'new');
     $this->assertSame(DiffArray::diffAssocRecursive($this->array1, $this->array2), $expected);
 }
 /**
  * Determines if a setting overrides the default value.
  *
  * @param string $name
  *   The name of the setting to check.
  * @param mixed $value
  *   The new value to check.
  *
  * @return bool
  *   TRUE or FALSE
  */
 public function overridesValue($name, $value)
 {
     return !!DiffArray::diffAssocRecursive([$name => $value], [$name => $this->get($name)]);
 }
Ejemplo n.º 4
0
 /**
  * Determines if a setting overrides the default value.
  *
  * @param string $name
  *   The name of the setting to check.
  * @param mixed $value
  *   The new value to check.
  *
  * @return bool
  *   TRUE or FALSE
  */
 public function overridesValue($name, $value)
 {
     // Retrieve the currently stored value for comparison purposes.
     $current_value = $this->get($name);
     // Due to the nature of DiffArray::diffAssocRecursive, if the provided
     // value is an empty array, it cannot be iterated over to determine if
     // the values are different. Instead, it must be checked explicitly.
     // @see https://www.drupal.org/node/2771121
     if ($value === [] && $current_value !== []) {
         return TRUE;
     }
     // Otherwise, determine if value is overridden by any array differences.
     return !!DiffArray::diffAssocRecursive([$name => $value], [$name => $current_value]);
 }