Browse Source

Handle empty nodes

pull/10/head
Richard Dern 3 months ago
parent
commit
99ff9071a3
  1. 24
      package/Concerns/HasLinkTags.php
  2. 14
      package/Concerns/HasMetaTags.php

24
package/Concerns/HasLinkTags.php

@ -17,21 +17,27 @@ trait HasLinkTags
/**
* Find and parse link tags.
*
* Chainable method.
*
* @return self
*/
protected function findLinkTags()
protected function findLinkTags(): self
{
$nodes = $this->findNodes('//head/link');
$this->linkTagsArray = [];
foreach ($nodes as $node) {
$data = $this->domElementToArray($node);
$link = new LinkTag();
$nodes = $this->findNodes('//head/link');
if ($nodes) {
foreach ($nodes as $node) {
$data = $this->domElementToArray($node);
$link = new LinkTag();
$link->setBaseAttributes($this->baseAttributes)
->forceFill($data);
$link->setBaseAttributes($this->baseAttributes)
->forceFill($data);
$this->linkTagsArray[] = $link;
$this->linkTagsArray[] = $link;
}
}
$this->setAttribute('linkTags', collect($this->linkTagsArray)->sortKeys()->all());

14
package/Concerns/HasMetaTags.php

@ -26,14 +26,16 @@ trait HasMetaTags
$nodes = $this->findNodes('//head/meta');
foreach ($nodes as $node) {
$data = $this->domElementToArray($node);
$meta = new MetaTag();
if ($nodes) {
foreach ($nodes as $node) {
$data = $this->domElementToArray($node);
$meta = new MetaTag();
$meta->setBaseAttributes($this->baseAttributes)
->forceFill($data);
$meta->setBaseAttributes($this->baseAttributes)
->forceFill($data);
$this->metaTagsArray[] = $meta;
$this->metaTagsArray[] = $meta;
}
}
$this->setAttribute('metaTags', $this->metaTagsArray);

Loading…
Cancel
Save