Skip to content

Commit

Permalink
Fixes an issue where Retcon could throw an exception if given a NULL …
Browse files Browse the repository at this point in the history
…value instead of a string. Bump to 2.0.7
  • Loading branch information
mmikkel committed Aug 7, 2018
1 parent 4cf83d5 commit 517bb62
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Retcon Changelog

## 2.0.7 - 2018-08-07
### Fixed
- Fixes an issue where Retcon could throw an exception if given a NULL value instead of a string (e.g. if a Redactor field had been added to a Field Layout, without re-saving the entries)

## 2.0.6 - 2018-08-05
### Fixed
- Fixes an issue where Retcon would attempt to use Imager for transforms, even if Imager was not installed or deactivated
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mmikkel/retcon",
"description": "Powerful Twig filters for mutating and querying HTML",
"type": "craft-plugin",
"version": "2.0.6",
"version": "2.0.7",
"keywords": [
"craft",
"cms",
Expand Down
17 changes: 13 additions & 4 deletions src/models/RetconSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class RetconSettings extends Model
{

/**
* @var string
* @var string|null
*/
public $baseTransformPath = '@webroot';

/**
* @var string
* @var string|null
*/
public $baseTransformUrl = '@web';

Expand All @@ -42,9 +42,18 @@ public function __construct($config = [])
public function init()
{
parent::init();

$this->useImager = $this->useImager && Craft::$app->getPlugins()->getPlugin('imager');
$this->baseTransformPath = Craft::getAlias($this->baseTransformPath);
$this->baseTransformUrl = Craft::getAlias($this->baseTransformUrl);

$baseTransformPath = Craft::getAlias($this->baseTransformPath);
if ($baseTransformPath) {
$this->baseTransformPath = $baseTransformPath;
}

$baseTransformUrl = Craft::getAlias($this->baseTransformUrl);
if ($baseTransformUrl) {
$this->baseTransformUrl = $baseTransformUrl;
}
}

}
68 changes: 34 additions & 34 deletions src/services/RetconService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class RetconService extends Component
{

/**
* @param string $html
* @param string|null $html
* @param $args
* @return mixed
* @throws Exception
*/
public function retcon(string $html, ...$args)
public function retcon($html, ...$args)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -79,18 +79,18 @@ public function retcon(string $html, ...$args)
* transform
* Applies an image transform to all images (or all nodes matching the passed selector(s))
*
* @param string $html
* @param string|null $html
* @param string|array $transform
* @param string|array $selector
* @param array $imagerTransformDefaults
* @param array $imagerConfigOverrides
* @return \Twig_Markup
* @throws \craft\errors\AssetTransformException
*/
public function transform(string $html, $transform, $selector = 'img', array $imagerTransformDefaults = [], array $imagerConfigOverrides = [])
public function transform($html, $transform, $selector = 'img', array $imagerTransformDefaults = [], array $imagerConfigOverrides = [])
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public function transform(string $html, $transform, $selector = 'img', array $im
* srcset
* Creates a srcset attribute for all images (or all nodes matching the selector(s) passed) with the proper transforms
*
* @param string $html
* @param string|null $html
* @param string|array $transforms
* @param string|array $selector
* @param string $sizes
Expand All @@ -147,10 +147,10 @@ public function transform(string $html, $transform, $selector = 'img', array $im
* @param array $configOverrides
* @return \Twig_Markup
*/
public function srcset(string $html, $transforms, $selector = 'img', $sizes = '100w', $base64src = false, $transformDefaults = [], $configOverrides = [])
public function srcset($html, $transforms, $selector = 'img', $sizes = '100w', $base64src = false, $transformDefaults = [], $configOverrides = [])
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -231,16 +231,16 @@ public function srcset(string $html, $transforms, $selector = 'img', $sizes = '1
* lazy
* Prepares all images (or all nodes matching the selector(s) passed) by swapping out the `src` attribute with a base64 encoded, transparent SVG. The original source will be retained in a data attribute
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @param string $className
* @param string $attributeName
* @return \Twig_Markup
*/
public function lazy(string $html, $selector = 'img', string $className = 'lazyload', string $attributeName = 'src')
public function lazy($html, $selector = 'img', string $className = 'lazyload', string $attributeName = 'src')
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -274,16 +274,16 @@ public function lazy(string $html, $selector = 'img', string $className = 'lazyl
* autoAlt
* Attempts to auto-generate alternative text for all images (or all elements matching the $selector attribute).
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @param string $field
* @param bool $overwrite
* @return \Twig_Markup
*/
public function autoAlt(string $html, $selector = 'img', string $field = 'title', bool $overwrite = false)
public function autoAlt($html, $selector = 'img', string $field = 'title', bool $overwrite = false)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -318,16 +318,16 @@ public function autoAlt(string $html, $selector = 'img', string $field = 'title'
* attr
* Adds (to) or replaces one or many attributes for one or many selectors
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @param array $attributes
* @param bool $overwrite
* @return \Twig_Markup
*/
public function attr(string $html, $selector, array $attributes, bool $overwrite = true)
public function attr($html, $selector, array $attributes, bool $overwrite = true)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -364,15 +364,15 @@ public function attr(string $html, $selector, array $attributes, bool $overwrite
* renameAttr
* Renames attributes for matching selector(s)
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @param array $attributes
* @return \Twig_Markup
*/
public function renameAttr($html, $selector, array $attributes)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand All @@ -399,14 +399,14 @@ public function renameAttr($html, $selector, array $attributes)
* remove
* Remove all elements matching given selector(s)
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @return \Twig_Markup
*/
public function remove($html, $selector)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand All @@ -426,14 +426,14 @@ public function remove($html, $selector)
* only
* Remove everything except nodes matching given selector(s)
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @return \Twig_Markup
*/
public function only($html, $selector)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -464,15 +464,15 @@ public function only($html, $selector)
* change
* Changes tag type/name for given selector(s). Can also remove tags (whilst retaining their contents) by passing `false` for the $toTag parameter
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @param string|bool $toTag
* @return \Twig_Markup
*/
public function change($html, $selector, $toTag)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -516,15 +516,15 @@ public function change($html, $selector, $toTag)
* wrap
* Wraps all nodes matching the given selector(s) in a container
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @param string $container
* @return \Twig_Markup
*/
public function wrap($html, $selector, $container)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -561,14 +561,14 @@ public function wrap($html, $selector, $container)
* unwrap
* Removes the parent of all nodes matching given selector(s), retaining all child nodes
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @return \Twig_Markup
*/
public function unwrap($html, $selector)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -601,7 +601,7 @@ public function unwrap($html, $selector)
* inject
* Injects string value (could be HTML!) into all nodes matching given selector(s)
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @param string $toInject
* @param bool $overwrite
Expand All @@ -610,7 +610,7 @@ public function unwrap($html, $selector)
public function inject($html, $selector, $toInject, $overwrite = false)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down Expand Up @@ -665,14 +665,14 @@ public function inject($html, $selector, $toInject, $overwrite = false)
* removeEmpty
* Removes empty nodes matching given selector(s), or all empty nodes if no selector
*
* @param string $html
* @param string|null $html
* @param string|array $selector
* @return \Twig_Markup
*/
public function removeEmpty($html, $selector = null)
{

if (!$html) {
if (!$html = (string)$html) {
return TemplateHelper::raw('');
}

Expand Down

0 comments on commit 517bb62

Please sign in to comment.