Skip to content

Commit

Permalink
Load svg's with nested elements, filter svg's by id, code clean-up (a…
Browse files Browse the repository at this point in the history
…rbory#87)

* load svg with nested elements, filter svg by id

* Code clean-up
  • Loading branch information
danielsGrietins authored and strads10 committed Aug 14, 2018
1 parent a9e7a20 commit 1b2baca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Admin/Form/Fields/Renderer/IconPickerRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ protected function getSvgIconElement( $id )
return Html::div()->addClass( 'element' );
}

$content = $iconNode->path->asXML();
$node = simplexml_load_string($iconNode->asXML());
$path = array_first($node->xpath('/symbol//path[@d]'));

if( $path )
{
$content = $path->asXML();
}
else
{
return Html::div()->addClass( 'element' );
}

$attributes = $iconNode->attributes();
$width = (int) $attributes->width;
Expand Down
20 changes: 20 additions & 0 deletions src/Admin/Form/Fields/SpriteIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class SpriteIcon extends Select
*/
protected $spritePath;

/**
* @var string
*/
protected $filter;

/**
* @param string $name
*/
Expand All @@ -34,6 +39,16 @@ public function sprite( string $path ): self
return $this;
}

/**
* @return $this
*/
public function filter( string $filter )
{
$this->filter = $filter;

return $this;
}

/**
* @return Collection
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -104,6 +119,11 @@ protected function getIconIds(): Collection
}
}

if( $this->filter && !str_contains($id, $this->filter) )
{
continue;
}

if( $id )
{
$ids->push( $id );
Expand Down

0 comments on commit 1b2baca

Please sign in to comment.