Added support to set classes and id on a medium object

This commit is contained in:
Andy Miller
2015-11-29 20:00:16 -07:00
parent fc7017f822
commit 3a7abeb18b

View File

@@ -214,8 +214,9 @@ class Medium extends Data implements RenderableInterface
else
$style .= $key . ': ' . $value . ';';
}
if ($style)
if ($style) {
$attributes['style'] = $style;
}
if (empty($attributes['title'])) {
if (!empty($title)) {
@@ -392,6 +393,38 @@ class Medium extends Data implements RenderableInterface
return $this->link($reset, $attributes);
}
/**
* Add a class to the element from Markdown or Twig
* Example: ![Example](myimg.png?classes=float-left) or ![Example](myimg.png?classes=myclass1,myclass2)
*
* @return $this
*/
public function classes()
{
$classes = func_get_args();
if (!empty($classes)) {
$this->attributes['class'] = implode(',', (array)$classes);
}
return $this;
}
/**
* Add an id to the element from Markdown or Twig
* Example: ![Example](myimg.png?id=primary-img)
*
* @param $id
* @return $this
*/
public function id($id)
{
if (is_string($id)) {
$this->attributes['id'] = trim($id);
}
return $this;
}
/**
* Allows to add an inline style attribute from Markdown or Twig
* Example: ![Example](myimg.png?style=float:left)