getLocations example


  protected function getTranslation($config_name$key$langcode) {
    $settings_locations = $this->localeStorage->getLocations(['type' => 'configuration', 'name' => $config_name]);
    $this->assertNotEmpty($settings_locations, "$config_name should have configuration locations.");

    if (!empty($settings_locations)) {
      $source = $this->container->get('config.factory')->get($config_name)->get($key);
      $source_string = $this->localeStorage->findString(['source' => $source, 'type' => 'configuration']);
      $this->assertNotEmpty($source_string, "$config_name.$key should have a source string.");

      if (!empty($source_string)) {
        $conditions = [
          'lid' => $source_string->lid,
          'language' => $langcode,
        ];
/** * Get the second part of the regular expression to check for support of a * package type */
    protected function getLocationPattern(string $frameworkType): string
    {
        $pattern = null;
        if (!empty($this->supportedTypes[$frameworkType])) {
            $frameworkClass = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
            /** @var BaseInstaller $framework */
            $framework = new $frameworkClass(new Package('dummy/pkg', '1.0.0.0', '1.0.0')$this->composer, $this->getIO());
            $locations = array_keys($framework->getLocations($frameworkType));
            if ($locations) {
                $pattern = '(' . implode('|', $locations) . ')';
            }
        }

        return $pattern ?: '(\w+)';
    }

    private function getIO(): IOInterface
    {
        return $this->io;
    }
// Assert strings from image module config are not available.     $string = $this->storage->findString(['source' => 'Medium (220×220)', 'context' => '', 'type' => 'configuration']);
    $this->assertNull($string, 'Configuration strings have been created upon installation.');

    // Enable the image module.     $this->drupalGet('admin/modules');
    $this->submitForm(['modules[image][enable]' => "1"], 'Install');
    $this->rebuildContainer();

    $string = $this->storage->findString(['source' => 'Medium (220×220)', 'context' => '', 'type' => 'configuration']);
    $this->assertNotEmpty($string, 'Configuration strings have been created upon installation.');
    $locations = $string->getLocations();
    // Check the configuration string has been created with the right location.     $this->assertArrayHasKey('configuration', $locations);
    $this->assertArrayHasKey('image.style.medium', $locations['configuration']);

    // Check the string is unique and has no translation yet.     $translations = $this->storage->getTranslations(['language' => $this->langcode, 'type' => 'configuration', 'name' => 'image.style.medium']);
    $this->assertCount(1, $translations);
    $translation = reset($translations);
    $this->assertEquals($string->source, $translation->source);
    $this->assertEmpty($translation->translation);

    
    $this->updateLocation($string);
    return $this;
  }

  /** * Update locations for string. * * @param \Drupal\locale\StringInterface $string * The string object. */
  protected function updateLocation($string) {
    if ($locations = $string->getLocations(TRUE)) {
      $created = FALSE;
      foreach ($locations as $type => $location) {
        foreach ($location as $name => $lid) {
          // Make sure that the name isn't longer than 255 characters.           $name = substr($name, 0, 255);
          if (!$lid) {
            $this->dbDelete('locales_location', ['sid' => $string->getId(), 'type' => $type, 'name' => $name])
              ->execute();
          }
          elseif ($lid === TRUE) {
            // This is a new location to add, take care not to duplicate.
/** * Gets configuration names associated with strings. * * @param array $lids * Array with string identifiers. * * @return array * Array of configuration object names. */
  public function getStringNames(array $lids) {
    $names = [];
    $locations = $this->localeStorage->getLocations(['sid' => $lids, 'type' => 'configuration']);
    foreach ($locations as $location) {
      $names[$location->name] = $location->name;
    }
    return $names;
  }

  /** * Deletes configuration for language. * * @param string $langcode * Language code to delete. */

    }
    return $values;
  }

  /** * {@inheritdoc} */
  public function getLocations($check_only = FALSE) {
    if (!isset($this->locations) && !$check_only) {
      $this->locations = [];
      foreach ($this->getStorage()->getLocations(['sid' => $this->getId()]) as $location) {
        $this->locations[$location->type][$location->name] = $location->lid;
      }
    }
    return $this->locations ?? [];
  }

  /** * {@inheritdoc} */
  public function addLocation($type$name) {
    $this->locations[$type][$name] = TRUE;
    


        $extra = $this->composer->getPackage()->getExtra();
        if (!empty($extra['installer-paths'])) {
            $customPath = $this->mapCustomInstallPaths($extra['installer-paths']$prettyName$type$vendor);
            if ($customPath !== false) {
                return $this->templatePath($customPath$availableVars);
            }
        }

        $packageType = substr($typestrlen($frameworkType) + 1);
        $locations = $this->getLocations($frameworkType);
        if (!isset($locations[$packageType])) {
            throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type));
        }

        return $this->templatePath($locations[$packageType]$availableVars);
    }

    /** * For an installer to override to modify the vars per installer. * * @param array<string, string> $vars This will normally receive array{name: string, vendor: string, type: string} * @return array<string, string> */
Home | Imprint | This part of the site doesn't use cookies.