From 3a7abeb18b11ccb7e672cd098fd12e75d43198e2 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 29 Nov 2015 20:00:16 -0700 Subject: [PATCH] Added support to set classes and id on a medium object --- system/src/Grav/Common/Page/Medium/Medium.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index b36864c27..a5e4001a7 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -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)