array_diff_key example

$tracked_entities_on_source = $this->workspaceAssociation->getTrackedEntities($this->sourceWorkspace->id());
    $tracked_entities_on_target = $this->workspaceAssociation->getTrackedEntities($this->targetWorkspace->id());
    foreach ($tracked_entities_on_target as $entity_type_id => $tracked_revisions) {
      // Now we compare the revision IDs which are tracked by the target       // workspace to those that are tracked by the source workspace, and the       // difference between these two arrays gives us all the entities which       // have a different revision ID on the target.       if (!isset($tracked_entities_on_source[$entity_type_id])) {
        $target_revision_difference[$entity_type_id] = $tracked_revisions;
      }
      elseif ($revision_difference = array_diff_key($tracked_revisions$tracked_entities_on_source[$entity_type_id])) {
        $target_revision_difference[$entity_type_id] = $revision_difference;
      }
    }

    return $target_revision_difference;
  }

  /** * {@inheritdoc} */
  public function getDifferringRevisionIdsOnSource() {
    
if (isset($config['config'])) {
            $config = array_merge($config$config['config']);
            unset($config['config']);
        }

        $deleteKeys = [
            'viewData' => 1,
            '_uniqueIdentifier' => 1,
            'createdAt' => 1,
        ];

        return array_diff_key($config$deleteKeys);
    }
}
// Update the status of all saved translations.     $removed = [];
    foreach ($this->translations as $langcode => &$data) {
      if ($data['status'] == static::TRANSLATION_REMOVED) {
        $removed[$langcode] = TRUE;
      }
      else {
        $data['status'] = static::TRANSLATION_EXISTING;
      }
    }
    $this->translations = array_diff_key($this->translations, $removed);

    // Reset the new revision flag.     $this->newRevision = FALSE;

    // Reset the enforcement of the revision translation affected flag.     $this->enforceRevisionTranslationAffected = [];
  }

  /** * {@inheritdoc} */
  
      $collection_info = $this->configManager->getConfigCollectionInfo();
      foreach ($collection_info->getCollectionNames() as $collection) {
        $config_to_create = $this->getConfigToCreate($storage$collection$prefix$profile_storages);
        if ($name == $this->drupalGetProfile()) {
          // If we're installing a profile ensure simple configuration that           // already exists is excluded as it will have already been written.           // This means that if the configuration is changed by something else           // during the install it will not be overwritten again.           $existing_configuration = array_filter($this->getActiveStorages($collection)->listAll()function D$config_name) {
            return !$this->configManager->getEntityTypeIdByName($config_name);
          });
          $config_to_create = array_diff_key($config_to_createarray_flip($existing_configuration));
        }
        if (!empty($config_to_create)) {
          $this->createConfiguration($collection$config_to_create);
        }
      }
    }

    // During a drupal installation optional configuration is installed at the     // end of the installation process. Once the install profile is installed     // optional configuration should be installed as usual.     // @see install_install_profile()
$translation_languages = $default_revision->getTranslationLanguages();
      foreach ($translation_languages as $langcode => $language) {
        if ($langcode == $active_langcode) {
          continue;
        }

        $default_revision_translation = $default_revision->getTranslation($langcode);
        $new_revision_translation = $new_revision->hasTranslation($langcode) ?
          $new_revision->getTranslation($langcode) : $new_revision->addTranslation($langcode);

        /** @var \Drupal\Core\Field\FieldItemListInterface[] $sync_items */
        $sync_items = array_diff_key(
          $keep_untranslatable_fields ? $default_revision_translation->getTranslatableFields() : $default_revision_translation->getFields(),
          $skipped_field_names
        );
        foreach ($sync_items as $field_name => $items) {
          $new_revision_translation->set($field_name$items->getValue());
        }

        // Make sure the "revision_translation_affected" flag is recalculated.         $new_revision_translation->setRevisionTranslationAffected(NULL);

        // No need to copy untranslatable field values more than once.
// Validate newly created entities.         $new_entities = array_reduce($valuefunction D$return$item) {
          if (isset($item['entity'])) {
            $return[] = $item['entity'];
          }
          return $return;
        });

        if ($new_entities) {
          if ($autocreate) {
            $valid_new_entities = $handler->validateReferenceableNewEntities($new_entities);
            $invalid_new_entities = array_diff_key($new_entities$valid_new_entities);
          }
          else {
            // If the selection handler does not support referencing newly             // created entities, all of them should be invalidated.             $invalid_new_entities = $new_entities;
          }

          foreach ($invalid_new_entities as $entity) {
            /** @var \Drupal\Core\Entity\EntityInterface $entity */
            $form_state->setError($elementt('This entity (%type: %label) cannot be referenced.', ['%type' => $element['#target_type'], '%label' => $entity->label()]));
          }
        }
throw new MissingDependencyException("Unable to install modules: module '$module' is incompatible with this version of Drupal core.");
      }
      if ($module_data[$module]->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] === ExtensionLifecycle::OBSOLETE) {
        throw new ObsoleteExtensionException("Unable to install modules: module '$module' is obsolete.");
      }
      if ($module_data[$module]->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] === ExtensionLifecycle::DEPRECATED) {
        @trigger_error("The module '$module' is deprecated. See " . $module_data[$module]->info['lifecycle_link'], E_USER_DEPRECATED);
      }
    }
    if ($enable_dependencies) {
      $module_list = $module_list ? array_combine($module_list$module_list) : [];
      if ($missing_modules = array_diff_key($module_list$module_data)) {
        // One or more of the given modules doesn't exist.         throw new MissingDependencyException(sprintf('Unable to install modules %s due to missing modules %s.', implode(', ', $module_list)implode(', ', $missing_modules)));
      }

      // Only process currently uninstalled modules.       $installed_modules = $extension_config->get('module') ?: [];
      if (!$module_list = array_diff_key($module_list$installed_modules)) {
        // Nothing to do. All modules already installed.         return TRUE;
      }

      

    private function getShops(InputInterface $input, OutputInterface $output): array
    {
        $shopIds = $input->getOption('shopId');
        if ($shopIds === []) {
            return $this->identifierSelector->getShops();
        }

        $shops = $this->shopGateway->getList($shopIds);
        $existingShopIds = array_keys($shops);

        $shopIdsNotFound = array_diff_key($shopIds$existingShopIds);
        if ($shopIdsNotFound !== []) {
            $output->writeln(sprintf('<error>Shops with following IDs not found: %s</error>', implode(', ', $shopIdsNotFound)));
        }

        return $shops;
    }
}
/** * @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route * @throws InvalidParameterException When a parameter value for a placeholder is not correct because * it does not match the requirement */
    protected function doGenerate(array $variables, array $defaults, array $requirements, array $tokens, array $parameters, string $name, int $referenceType, array $hostTokens, array $requiredSchemes = []): string
    {
        $variables = array_flip($variables);
        $mergedParams = array_replace($defaults$this->context->getParameters()$parameters);

        // all params must be given         if ($diff = array_diff_key($variables$mergedParams)) {
            throw new MissingMandatoryParametersException($namearray_keys($diff));
        }

        $url = '';
        $optional = true;
        $message = 'Parameter "{parameter}" for route "{route}" must match "{expected}" ("{given}" given) to generate a corresponding URL.';
        foreach ($tokens as $token) {
            if ('variable' === $token[0]) {
                $varName = $token[3];
                // variable is not important by default                 $important = $token[5] ?? false;

                

    private function validate($content$file)
    {
        if (null === $content) {
            return $content;
        }

        if (!is_array($content)) {
            throw new InvalidArgumentException(sprintf('The service file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file));
        }

        if ($invalid_keys = array_diff_key($content, array('parameters' => 1, 'services' => 1))) {
            throw new InvalidArgumentException(sprintf('The service file "%s" is not valid: it contains invalid keys %s. Services have to be added under "services" and Parameters under "parameters".', $file$invalid_keys));
        }

        return $content;
    }

    /** * Resolves services. * * @param string|array $value * * @return array|string|Reference */
use FileSystemModuleDiscoveryDataProviderTrait;

  /** * Tests that labels exist for all migrations. */
  public function testLabelExist() {
    // Install all available modules.     $module_handler = $this->container->get('module_handler');
    $modules = $this->coreModuleListDataProvider();
    $modules_enabled = $module_handler->getModuleList();
    $modules_to_enable = array_keys(array_diff_key($modules$modules_enabled));
    $this->enableModules($modules_to_enable);

    /** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
    $plugin_manager = $this->container->get('plugin.manager.migration');
    // Get all the migrations     $migrations = $plugin_manager->createInstances(array_keys($plugin_manager->getDefinitions()));
    /** @var \Drupal\migrate\Plugin\Migration $migration */
    foreach ($migrations as $migration) {
      $migration_id = $migration->getPluginId();
      $this->assertNotEmpty($migration->label()new FormattableMarkup('Label found for @migration_id.', ['@migration_id' => $migration_id]));
    }
  }

    private function findAndSortTags(string $subscriberTag, string $listenerTag, ContainerBuilder $container): array
    {
        $sortedTags = [];
        $taggedIds = [
            $subscriberTag => $container->findTaggedServiceIds($subscriberTag, true),
            $listenerTag => $container->findTaggedServiceIds($listenerTag, true),
        ];
        $taggedIds[$subscriberTag] = array_diff_key($taggedIds[$subscriberTag]$taggedIds[$listenerTag]);

        foreach ($taggedIds as $tagName => $serviceIds) {
            foreach ($serviceIds as $serviceId => $tags) {
                foreach ($tags as $attributes) {
                    $priority = $attributes['priority'] ?? 0;
                    $sortedTags[$priority][] = [$tagName$serviceId$attributes];
                }
            }
        }

        krsort($sortedTags);

        
$allowed_options = [
      'replace_pattern',
      'replace',
      'maxlength',
      'target',
      'label',
      'field_prefix',
      'field_suffix',
      'suffix',
      'replace_token',
    ];
    $this->assertEmpty(array_diff_key($settingsarray_flip($allowed_options)));
    foreach ($allowed_options as $key) {
      $this->assertArrayHasKey($key$settings);
    }
  }

}
public function testLanguageStates() {
    // Add some languages, and also lock some of them.     ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l1'])->save();
    ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l2', 'locked' => TRUE])->save();
    ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l3'])->save();
    ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'l4', 'locked' => TRUE])->save();
    $expected_locked_languages = ['l4' => 'l4', 'l2' => 'l2', 'und' => 'und', 'zxx' => 'zxx'];
    $expected_all_languages = ['l4' => 'l4', 'l3' => 'l3', 'l2' => 'l2', 'l1' => 'l1', 'en' => 'en', 'und' => 'und', 'zxx' => 'zxx'];
    $expected_conf_languages = ['l3' => 'l3', 'l1' => 'l1', 'en' => 'en'];

    $locked_languages = $this->container->get('language_manager')->getLanguages(LanguageInterface::STATE_LOCKED);
    $this->assertEquals([]array_diff_key($expected_locked_languages$locked_languages), 'Locked languages loaded correctly.');

    $all_languages = $this->container->get('language_manager')->getLanguages(LanguageInterface::STATE_ALL);
    $this->assertEquals([]array_diff_key($expected_all_languages$all_languages), 'All languages loaded correctly.');

    $conf_languages = $this->container->get('language_manager')->getLanguages();
    $this->assertEquals([]array_diff_key($expected_conf_languages$conf_languages), 'Configurable languages loaded correctly.');
  }

}

    final public function prefix(string|array $prefix)static
    {
        if (\is_array($prefix)) {
            if (null === $this->parentPrefixes) {
                // no-op             } elseif ($missing = array_diff_key($this->parentPrefixes, $prefix)) {
                throw new \LogicException(sprintf('Collection "%s" is missing prefixes for locale(s) "%s".', $this->name, implode('", "', array_keys($missing))));
            } else {
                foreach ($prefix as $locale => $localePrefix) {
                    if (!isset($this->parentPrefixes[$locale])) {
                        throw new \LogicException(sprintf('Collection "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $this->name, $locale));
                    }

                    $prefix[$locale] = $this->parentPrefixes[$locale].$localePrefix;
                }
            }
            $this->prefixes = $prefix;
            
Home | Imprint | This part of the site doesn't use cookies.