Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Don't show prefix and postfix if there is no placeholder items. #133

Closed
wants to merge 7 commits into from

Conversation

AndyDune
Copy link
Contributor

@AndyDune AndyDune commented Aug 14, 2017

For show h1 in layout with set in view file.

<?= $this->placeholder('h1')->setPrefix('<h1>')->setPostfix('</h1>'); ?>

@@ -118,6 +118,10 @@ public function toString($indent = null)
: $this->getIndent();

$items = $this->getArrayCopy();
// If we don't have items - do not show prefix and postfix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no item is present, then this check should the first step in this method. You can use $this->count().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide also an unit test for this new behaviour. Thanks!

Copy link
Contributor Author

@AndyDune AndyDune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check the last commit.

// If we don't have items - do not show prefix and postfix
if (!count($items)) {
if (!$this->count()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this check before $indent = ($indent !== null) (line 116) and add a whitespace after !.

return '';
}

$itemsToString = implode($this->getSeparator(), $this->getArrayCopy());
// todo check empty $itemsToString after trim() to return ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If items with whitespace are added, then there is a reason for it and we should allow the rendering. Please undo this changes.

Copy link
Contributor Author

@AndyDune AndyDune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check please. I've made changes.

// If we don't have items - do not show prefix and postfix
if (!$this->count()) {
return '';
}

$itemsToString = implode($this->getSeparator(), $this->getArrayCopy());
// todo check empty $itemsToString after trim() to return ''
$indent = ($indent !== null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we should avoid the negative check:

$indent = $indent === null
    ? $this->getIndent()
    : $this->getWhitespace($indent);

Copy link
Contributor Author

@AndyDune AndyDune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check it please.

@@ -113,8 +113,7 @@ public function __toString()
*/
public function toString($indent = null)
{
// If we don't have items - do not show prefix and postfix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment was good.

@froschdesign froschdesign added this to the 2.10.0 milestone Sep 15, 2017
weierophinney added a commit that referenced this pull request Jan 17, 2018
Don't show prefix and postfix if there is no placeholder items.
weierophinney added a commit that referenced this pull request Jan 17, 2018
weierophinney added a commit that referenced this pull request Jan 17, 2018
@weierophinney
Copy link
Member

Thanks, @AndyDune; merged to develop for release with 2.10.0, as it is a slight change in behavior.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants