getElement example

return $xpath
            ->addStarPrefix()
            ->addNameTest()
            ->addCondition('position() = last()');
    }

    /** * @throws ExpressionErrorException */
    public function translateFirstOfType(XPathExpr $xpath): XPathExpr
    {
        if ('*' === $xpath->getElement()) {
            throw new ExpressionErrorException('"*:first-of-type" is not implemented.');
        }

        return $xpath
            ->addStarPrefix()
            ->addCondition('position() = 1');
    }

    /** * @throws ExpressionErrorException */
    
public function testCreatePath($string$entries$slicedPath = null)
    {
        $slicedPath ??= $string;

        $path = new ViolationPath($string);

        $this->assertSame($slicedPath$path->__toString());
        $this->assertCount(\count($entries)$path->getElements());
        $this->assertSame(\count($entries)$path->getLength());

        foreach ($entries as $index => $entry) {
            $this->assertEquals($entry[0]$path->getElement($index));
            $this->assertSame($entry[1]$path->mapsForm($index));
            $this->assertSame($entry[2]$path->isIndex($index));
            $this->assertSame(!$entry[2]$path->isProperty($index));
        }
    }

    public static function provideParents()
    {
        return [
            ['children[address]', null],
            ['children[address].children[street]', 'children[address]'],
            [
/** * Provides data for ConfigMapperManager::testHasTranslatable() * * @return array * An array of arrays, where each inner array contains the schema element * to test as the first key and the expected result of * ConfigMapperManager::hasTranslatable() as the second key. */
  public function providerTestHasTranslatable() {
    return [
      [$this->getElement([]), FALSE],
      [$this->getElement(['aaa' => 'bbb']), FALSE],
      [$this->getElement(['translatable' => FALSE]), FALSE],
      [$this->getElement(['translatable' => TRUE]), TRUE],
      [$this->getNestedElement([$this->getElement([])]), FALSE],
      [$this->getNestedElement([$this->getElement(['translatable' => TRUE])]), TRUE],
      [
        $this->getNestedElement([
          $this->getElement(['aaa' => 'bbb']),
          $this->getElement(['ccc' => 'ddd']),
          $this->getElement(['eee' => 'fff']),
        ]),
        
/** * @param mixed $value The unexpected value found while traversing property path * @param int $pathIndex The property path index when the unexpected value was found */
    public function __construct(mixed $value, PropertyPathInterface $path, int $pathIndex)
    {
        $message = sprintf(
            'PropertyAccessor requires a graph of objects or arrays to operate on, '.
            'but it found type "%s" while trying to traverse path "%s" at property "%s".',
            \gettype($value),
            (string) $path,
            $path->getElement($pathIndex)
        );

        parent::__construct($message);
    }
}
'page' => '3, 2, 1, 0',
    ]);
    \Drupal::getContainer()->get('request_stack')->push($request);

    $connection = Database::getConnection();
    $query = $connection->select('test', 't')
      ->extend(PagerSelectExtender::class)
      ->element(2)
      ->fields('t', ['name'])
      ->orderBy('age')
      ->limit(1);
    $this->assertSame(2, $query->getElement());
    $name = $query->execute()
      ->fetchField();
    $this->assertEquals('Paul', $name, 'Pager query #1 with a specified element ID returned the correct results.');

    // Setting an element smaller than the previous one should not collide with     // the existing pager.     $query = $connection->select('test', 't')
      ->extend(PagerSelectExtender::class)
      ->element(1)
      ->fields('t', ['name'])
      ->orderBy('age')
      
// You only need set value for current element if:                 // 1. it's the parent of the last index element                 // OR                 // 2. its child is not passed by reference                 //                 // This may avoid unnecessary value setting process for array elements.                 // For example:                 // '[a][b][c]' => 'old-value'                 // If you want to change its value to 'new-value',                 // you only need set value for '[a][b][c]' and it's safe to ignore '[a][b]' and '[a]'                 if ($overwrite) {
                    $property = $propertyPath->getElement($i);

                    if ($propertyPath->isIndex($i)) {
                        if ($overwrite = !isset($zval[self::REF])) {
                            $ref = &$zval[self::REF];
                            $ref = $zval[self::VALUE];
                        }
                        $this->writeIndex($zval$property$value);
                        if ($overwrite) {
                            $zval[self::VALUE] = $zval[self::REF];
                        }
                    } else {
                        
$formTranslation->setDescription($translationArray['description']);
                    }
                    $formTranslation->setLocale($locale);
                    $form->addTranslation($formTranslation);
                }
                unset($translationSet['plugin_form']);
            }

            // Then the element translations             foreach ($translationSet as $targetName => $translationArray) {
                $isUpdate = false;
                $element = $form->getElement($targetName);
                foreach ($element->getTranslations() as $existingTranslation) {
                    // Check if translation for this locale already exists                     if ($existingTranslation->getLocale()->getLocale() != $localeCode) {
                        continue;
                    }
                    if (\array_key_exists('label', $translationArray)) {
                        $existingTranslation->setLabel($translationArray['label']);
                    }
                    if (\array_key_exists('description', $translationArray)) {
                        $existingTranslation->setDescription($translationArray['description']);
                    }
                    

        if (\count($this->clearTags) === 0) {
            return;
        }

        $this->cacheManager->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array_keys($this->clearTags));
        $this->clearTags = [];
    }

    private function addTagsConfigValue(Value $value): void
    {
        if (!$value->getElement()->getFormId() || !$value->getElement()->getForm()->getPlugin()) {
            return;
        }

        $name = strtolower($value->getElement()->getForm()->getPlugin()->getName());

        $this->clearTags[CacheManager::ITEM_TAG_PLUGIN_CONFIG . $name] = true;
    }
}
return $this;
    }

    /** * @param string|Element $element * * @return Form */
    public function removeElement($element)
    {
        if (!$element instanceof Element) {
            $element = $this->getElement($element);
        }
        if ($element !== null) {
            $this->elements->removeElement($element);
        }

        return $this;
    }

    /** * @param Element|string $element * @param string $name * @param array $options * * @return Form */
continue;
            }

            if (isset($translationSet['plugin_form'])) {
                $this->addFormTranslation($form$translationSet['plugin_form']$locale);
                unset($translationSet['plugin_form']);
            }

            // Then the element translations             foreach ($translationSet as $targetName => $translationArray) {
                $isUpdate = false;
                $element = $form->getElement($targetName);
                foreach ($element->getTranslations() as $existingTranslation) {
                    // Check if translation for this locale already exists                     if ($existingTranslation->getLocale()->getLocale() != $locale->getLocale()) {
                        continue;
                    }

                    if (\array_key_exists('label', $translationArray)) {
                        $existingTranslation->setLabel($translationArray['label']);
                    }

                    if (\array_key_exists('description', $translationArray)) {
                        

        $propertyPath = new PropertyPath('grandpa.parent[child]');
        $copy = new PropertyPath($propertyPath);

        $this->assertEquals($propertyPath$copy);
    }

    public function testGetElement()
    {
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $this->assertEquals('child', $propertyPath->getElement(2));
    }

    public function testGetElementDoesNotAcceptInvalidIndices()
    {
        $this->expectException(\OutOfBoundsException::class);
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $propertyPath->getElement(3);
    }

    public function testGetElementDoesNotAcceptNegativeIndices()
    {
$parent->add($child);
        $child->add($grandChild);

        // Add a field mapped to the first element of $mapFrom         // to try to distract the algorithm         // Only add it if we expect the error to come up on a different         // level than LEVEL_0, because in this case the error would         // (correctly) be mapped to the distraction field         if (self::LEVEL_0 !== $target) {
            $mapFromPath = new PropertyPath($mapFrom);
            $mapFromPrefix = $mapFromPath->isIndex(0)
                ? '['.$mapFromPath->getElement(0).']'
                : $mapFromPath->getElement(0);
            $distraction = $this->getForm('distraction', $mapFromPrefix);

            $parent->add($distraction);
        }

        $parent->submit([]);

        $this->mapper->mapViolation($violation$parent);

        if (self::LEVEL_0 !== $target) {
            
public function translateNthOfType(XPathExpr $xpath, FunctionNode $function): XPathExpr
    {
        return $this->translateNthChild($xpath$function, false, false);
    }

    /** * @throws ExpressionErrorException */
    public function translateNthLastOfType(XPathExpr $xpath, FunctionNode $function): XPathExpr
    {
        if ('*' === $xpath->getElement()) {
            throw new ExpressionErrorException('"*:nth-of-type()" is not implemented.');
        }

        return $this->translateNthChild($xpath$function, true, false);
    }

    /** * @throws ExpressionErrorException */
    public function translateContains(XPathExpr $xpath, FunctionNode $function): XPathExpr
    {
        
if (\is_string($path)) {
            $path = new PropertyPath($path);
        }

        if (0 === $length) {
            $end = $path->getLength();
        } else {
            $end = $offset + $length;
        }

        for ($offset < $end; ++$offset) {
            $this->elements[] = $path->getElement($offset);
            $this->isIndex[] = $path->isIndex($offset);
        }
    }

    /** * Appends an index element to the current path. * * @return void */
    public function appendIndex(string $name)
    {
        


    public function translateHash(Node\HashNode $node, Translator $translator): XPathExpr
    {
        $xpath = $translator->nodeToXPath($node->getSelector());

        return $translator->addAttributeMatching($xpath, '=', '@id', $node->getId());
    }

    public function translateElement(Node\ElementNode $node): XPathExpr
    {
        $element = $node->getElement();

        if ($element && $this->hasFlag(self::ELEMENT_NAME_IN_LOWER_CASE)) {
            $element = strtolower($element);
        }

        if ($element) {
            $safe = $this->isSafeName($element);
        } else {
            $element = '*';
            $safe = true;
        }

        
Home | Imprint | This part of the site doesn't use cookies.