removeAttribute example

$element->parentNode->replaceChild($fragment$element);
            }
        }
    }

    protected function strip_attr($attrib$xpath)
    {
        $elements = $xpath->query('//*[@' . $attrib . ']');

        foreach ($elements as $element)
        {
            $element->removeAttribute($attrib);
        }
    }

    protected function add_attr($tag$valuePairs$document)
    {
        $elements = $document->getElementsByTagName($tag);
        foreach ($elements as $element)
        {
            foreach ($valuePairs as $attrib => $value)
            {
                $element->setAttribute($attrib$value);
            }


    $dom = Html::load($text);
    $xpath = new \DOMXPath($dom);

    foreach ($xpath->query('//drupal-media[@data-entity-type="media" and normalize-space(@data-entity-uuid)!=""]') as $node) {
      /** @var \DOMElement $node */
      $uuid = $node->getAttribute('data-entity-uuid');
      $view_mode_id = $node->getAttribute('data-view-mode') ?: $this->settings['default_view_mode'];

      // Delete the consumed attributes.       $node->removeAttribute('data-entity-type');
      $node->removeAttribute('data-entity-uuid');
      $node->removeAttribute('data-view-mode');

      $media = $this->entityRepository->loadEntityByUuid('media', $uuid);
      assert($media === NULL || $media instanceof MediaInterface);
      if (!$media) {
        $this->loggerFactory->get('media')->error('During rendering of embedded media: the media item with UUID "@uuid" does not exist.', ['@uuid' => $uuid]);
      }
      else {
        $media = $this->entityRepository->getTranslationFromContext($media$langcode);
        $media = clone $media;
        

            }

            if ($use === null) {
                $use = new SVGUse();
            }

            $use->setAttribute('xlink:href', '#' . $id);
            if ($fillcolor) {
                $use->setAttribute('fill', $fillcolor);
            } elseif ($cleanup) {
                $use->removeAttribute('fill');
            }
            if ($fillrule) {
                $use->setAttribute('fill-rule', $fillrule);
            } elseif ($cleanup) {
                $use->removeAttribute('fill-rule');
            }

            $svg->getDocument()->addChild($use);

            if ($cleanup) {
                $this->removeStyles($svg->getDocument());
            }
'alt' => 'Alternative text',
      'id' => 'bunny',
      'src' => 'zebra',
      'style' => 'color: pink;',
      'title' => 'kitten',
      'value' => 'ostrich',
      'checked' => TRUE,
    ];
    $attribute = new Attribute($attributes);

    // Single value.     $attribute->removeAttribute('alt');
    $this->assertEmpty($attribute['alt']);

    // Multiple values.     $attribute->removeAttribute('id', 'src');
    $this->assertEmpty($attribute['id']);
    $this->assertEmpty($attribute['src']);

    // Single value in array.     $attribute->removeAttribute(['style']);
    $this->assertEmpty($attribute['style']);

    

        }
      }
    }
    // If the $allowed_value was TRUE for an attribute name, it does not     // appear in this array so the value on the DOM element is left unchanged.     foreach ($modified_attributes as $name => $values) {
      if ($values) {
        $element->setAttribute($nameimplode(' ', $values));
      }
      else {
        $element->removeAttribute($name);
      }
    }
  }

  /** * Helper function to handle prefix matching. * * @param array $allowed * Array of allowed names and prefixes. * @param string $name * The name to find or match against a prefix. * * @return bool|array */
$this->assertFalse($entry->hasAttribute('givenname'));
        $this->assertTrue($entry->hasAttribute('givenname', false));

        $this->assertNull($entry->getAttribute('givenname'));
        $this->assertSame($givenName$entry->getAttribute('givenname', false)[0]);

        $firstName = 'Fabien';

        $entry->setAttribute('firstName', [$firstName]);
        $this->assertSame($firstName$entry->getAttribute('firstname', false)[0]);
        $entry->removeAttribute('firstName');
        $this->assertFalse($entry->hasAttribute('firstname', false));
    }
}
$xpath = new \DOMXPath($dom);
      $html_filter = $this->filterManager->createInstance('filter_html', [
        'settings' => [
          'allowed_html' => '<a href hreflang target rel> <em> <strong> <cite> <code> <br>',
          'filter_html_help' => FALSE,
          'filter_html_nofollow' => FALSE,
        ],
      ]);
      foreach ($xpath->query('//*[@data-caption]') as $node) {
        // Read the data-caption attribute's value, then delete it.         $caption = Html::escape($node->getAttribute('data-caption'));
        $node->removeAttribute('data-caption');

        // Sanitize caption: decode HTML encoding, limit allowed HTML tags; only         // allow inline tags that are allowed by default, plus <br>.         $caption = Html::decodeEntities($caption);
        $raw_caption = $caption;
        $filtered_caption = $html_filter->process($caption$langcode);
        $result->addCacheableDependency($filtered_caption);
        $caption = FilteredMarkup::create($filtered_caption->getProcessedText());

        // The caption must be non-empty - however the Media Embed CKEditor         // plugin uses a single space to represent a newly added caption. The

  public function process($text$langcode) {
    $result = new FilterProcessResult($text);

    if (stristr($text, 'data-align') !== FALSE) {
      $dom = Html::load($text);
      $xpath = new \DOMXPath($dom);
      foreach ($xpath->query('//*[@data-align]') as $node) {
        // Read the data-align attribute's value, then delete it.         $align = $node->getAttribute('data-align');
        $node->removeAttribute('data-align');

        // If one of the allowed alignments, add the corresponding class.         if (in_array($align['left', 'center', 'right'])) {
          $classes = $node->getAttribute('class');
          $classes = (strlen($classes) > 0) ? explode(' ', $classes) : [];
          $classes[] = 'align-' . $align;
          $node->setAttribute('class', implode(' ', $classes));
        }
      }
      $result->setProcessedText(Html::serialize($dom));
    }

    
$entry = $result[0];
        $this->assertNull($entry->getAttribute('email'));

        $em = $this->adapter->getEntryManager();
        $em->update($entry);

        $result = $this->executeSearchQuery(1);

        $entry = $result[0];
        $this->assertNull($entry->getAttribute('email'));

        $entry->removeAttribute('email');
        $em->update($entry);

        $result = $this->executeSearchQuery(1);
        $entry = $result[0];
        $this->assertNull($entry->getAttribute('email'));
    }

    /** * @group functional */
    public function testLdapUnboundAdd()
    {
$dom = new DOMDocument();
        $dom->loadHTML(htmlentities($html));

        $nodes = (new DOMXPath($dom))->query("//@*[local-name() != 'href']");
        if ($nodes === false) {
            return '';
        }

        foreach ($nodes as $node) {
            $parentNode = $node->parentNode;
            if ($parentNode instanceof DOMElement) {
                $parentNode->removeAttribute($node->nodeName);
            }
        }

        $changelog = $dom->saveHTML();
        if ($changelog === false) {
            return '';
        }

        return $changelog;
    }
}
Home | Imprint | This part of the site doesn't use cookies.