Skip to content
Snippets Groups Projects
Commit d310bb05 authored by Binoli Lalani's avatar Binoli Lalani Committed by Dave Reid
Browse files

Issue #3320371 by Dave Reid, Binoli Lalani: Fixed PHP strlen(): Passing null...

Issue #3320371 by Dave Reid, Binoli Lalani: Fixed PHP strlen(): Passing null to parameter #1 ($string) of type string is deprecated in DomHelperTrait.
parent c3b83b38
Branches
Tags
1 merge request!7Issue #3320371: strlen(): Passing null to parameter #1 ($string) of type string is deprecated
......@@ -12,7 +12,7 @@ function embed_requirements($phase): array {
$requirements = [];
if ($phase === 'runtime') {
// Since CKEditor5 is installed, perform a check for any icons that are not SVG files.
// Check for any icons that are not SVG files when CKEditor5 is installed.
if (\Drupal::moduleHandler()->moduleExists('ckeditor5')) {
$button_icons_not_svg = [];
/** @var \Drupal\embed\Entity\EmbedButton[] $buttons */
......
<?php
declare(strict_types = 1);
namespace Drupal\embed;
use Drupal\Component\Utility\Html;
......@@ -22,7 +24,7 @@ trait DomHelperTrait {
* @param string $name
* The new tag name.
*/
protected function changeNodeName(\DOMNode &$node, $name = 'div') {
protected function changeNodeName(\DOMNode &$node, string $name = 'div'): void {
if ($node->nodeName != $name) {
/** @var \DOMElement $replacement_node */
$replacement_node = $node->ownerDocument->createElement($name);
......@@ -55,7 +57,7 @@ trait DomHelperTrait {
* @param string $content
* The text or HTML that will replace the contents of $node.
*/
protected function setNodeContent(\DOMNode $node, $content) {
protected function setNodeContent(\DOMNode $node, string $content): void {
// Remove all children of the DOMNode.
while ($node->hasChildNodes()) {
$node->removeChild($node->firstChild);
......@@ -81,7 +83,7 @@ trait DomHelperTrait {
* @param string $content
* The text or HTML that will replace the contents of $node.
*/
protected function replaceNodeContent(\DOMNode &$node, $content) {
protected function replaceNodeContent(\DOMNode $node, string $content): void {
if (strlen($content)) {
// Load the content into a new DOMDocument and retrieve the DOM nodes.
$replacement_nodes = Html::load($content)->getElementsByTagName('body')
......@@ -112,7 +114,7 @@ trait DomHelperTrait {
* @return array
* The attributes as an associative array, keyed by the attribute names.
*/
public function getNodeAttributesAsArray(\DOMNode $node) {
public function getNodeAttributesAsArray(\DOMNode $node): array {
$return = [];
// Convert the data attributes to the context array.
......
......@@ -168,6 +168,7 @@ class EmbedButton extends ConfigEntityBase implements EmbedButtonInterface {
* Gets the file URL generator service.
*
* @return \Drupal\Core\File\FileUrlGeneratorInterface
* The file URL generator.
*/
protected function fileUrlGenerator() {
return \Drupal::service('file_url_generator');
......
......@@ -57,10 +57,9 @@ class DomHelperTraitTest extends UnitTestCase {
}
/**
* @return array
* @see ::testSetNodeContent()
* Data provider for testSetNodeContent().
*/
public function providerTestSetNodeContent() {
public function providerTestSetNodeContent(): array {
return [
'empty' => [
'',
......@@ -96,10 +95,9 @@ class DomHelperTraitTest extends UnitTestCase {
}
/**
* @return array
* @see ::testReplaceNodeContent()
* Data provider for testReplaceNodeContent().
*/
public function providerTestReplaceNodeContent() {
public function providerTestReplaceNodeContent(): array {
return [
'empty' => [
'',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment