Skip to content

Commit

Permalink
Merge pull request #2 from omerkocaoglu/master
Browse files Browse the repository at this point in the history
ADD RenderArrayIfNotEmptyModifier
  • Loading branch information
necipallef authored Jul 16, 2018
2 parents d775467 + 8cdb2b7 commit 8d7ea73
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Modifier/ModificationMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public function setRenderIfNotNull($property_name)
return $this->setModifier($property_name, new RenderIfNotNullModifier());
}

/**
* @param string $property_name
* @return ModificationMetadata
*/
public function setRenderArrayIfNotEmpty($property_name)
{
return $this->setModifier($property_name, new RenderArrayIfNotEmptyModifier());
}

/**
* @param string $property_name
* @param string[] $render_tag_list
Expand Down
4 changes: 2 additions & 2 deletions src/Modifier/RenderArrayIfNotEmptyModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class RenderArrayIfNotEmptyModifier extends ModifierBase
*/
public function apply($value, $selected_render_tag_list = [])
{
if (is_array($value) && count($value) === 0) {
$this->setShouldRender(false);
if (is_array($value)) {
$this->setShouldRender(count($value) > 0);
}
}
}
10 changes: 10 additions & 0 deletions src/Normalizer/NormalizationMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public function setRenderIfNotNull($property_name)
return $this;
}

/**
* @param string $property_name
* @return NormalizationMetadata
*/
public function setRenderArrayIfNotEmpty($property_name)
{
$this->modification_metadata->setRenderArrayIfNotEmpty($property_name);
return $this;
}

/**
* @param string $property_name
* @param string[] $render_tag_list
Expand Down

0 comments on commit 8d7ea73

Please sign in to comment.