Skip to content

Commit

Permalink
Adopt to yiisoft/html changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Feb 22, 2021
1 parent 7414614 commit e002020
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 166 deletions.
18 changes: 7 additions & 11 deletions src/Breadcrumbs.php
Expand Up @@ -47,11 +47,11 @@ protected function run(): string
$this->buildOptions();

return
Html::beginTag('nav', $this->options) . "\n" .
Html::beginTag('ul', $this->itemsOptions) . "\n" .
Html::openTag('nav', $this->options) . "\n" .
Html::openTag('ul', $this->itemsOptions) . "\n" .
implode('', $this->renderItems()) .
Html::endTag('ul') . "\n" .
Html::endTag('nav');
Html::closeTag('ul') . "\n" .
Html::closeTag('nav');
}

/**
Expand Down Expand Up @@ -199,9 +199,9 @@ private function renderIcon(string $icon, array $iconOptions): string
$html = '';

if ($icon !== '') {
$html = Html::beginTag('span', $iconOptions) .
$html = Html::openTag('span', $iconOptions) .
Html::tag('i', '', ['class' => $icon]) .
Html::endTag('span');
Html::closeTag('span');
}

return $html;
Expand Down Expand Up @@ -245,14 +245,10 @@ private function renderItem(array $link, string $template): string
$template = $link['template'];
}

if ($this->encodeLinks === false) {
$link['encode'] = false;
}

if (isset($link['url'])) {
$options = $link;
unset($options['template'], $options['label'], $options['url'], $options['icon']);
$linkHtml = Html::a($label, $link['url'], $options);
$linkHtml = Html::a($label, $link['url'], $options)->encode($this->encodeLinks)->render();
} else {
$linkHtml = $label;
}
Expand Down
40 changes: 20 additions & 20 deletions src/Dropdown.php
Expand Up @@ -234,10 +234,10 @@ public function triggerOptions(array $value): self
private function buildDropdown(): string
{
if ($this->encloseByContainer) {
$html = Html::beginTag('div', $this->options) . "\n";
$html = Html::openTag('div', $this->options) . "\n";
$html .= $this->buildDropdownTrigger();
$html .= $this->renderItems($this->items, $this->itemsOptions) . "\n";
$html .= Html::endTag('div');
$html .= Html::closeTag('div');
} else {
$html = $this->renderItems($this->items, $this->itemsOptions);
}
Expand All @@ -248,14 +248,14 @@ private function buildDropdown(): string
private function buildDropdownTrigger(): string
{
return
Html::beginTag('div', $this->triggerOptions) . "\n" .
Html::beginTag('button', $this->buttonOptions) . "\n" .
Html::openTag('div', $this->triggerOptions) . "\n" .
Html::openTag('button', $this->buttonOptions) . "\n" .
Html::tag('span', $this->buttonLabel, $this->buttonLabelOptions) . "\n" .
Html::beginTag('span', $this->buttonIconOptions) . "\n" .
Html::openTag('span', $this->buttonIconOptions) . "\n" .
Html::tag('i', '', $this->buttonIcon) . "\n" .
Html::endTag('span') . "\n" .
Html::endTag('button') . "\n" .
Html::endTag('div') . "\n";
Html::closeTag('span') . "\n" .
Html::closeTag('button') . "\n" .
Html::closeTag('div') . "\n";
}

private function buildOptions(): void
Expand Down Expand Up @@ -326,10 +326,6 @@ private function renderItems(array $items, array $itemsOptions = []): string
$active = ArrayHelper::getValue($item, 'active', false);
$disabled = ArrayHelper::getValue($item, 'disabled', false);

if ($this->encodeLinks === false) {
$linkOptions['encode'] = false;
}

Html::addCssClass($linkOptions, $this->itemClass);

if ($disabled) {
Expand All @@ -344,9 +340,13 @@ private function renderItems(array $items, array $itemsOptions = []): string
$url = $item['url'] ?? null;

if (empty($item['items'])) {
$lines[] = Html::a($label, $url, $linkOptions);
$lines[] = Html::a($label, $url, $linkOptions)
->encode($this->encodeLinks)
->render();
} else {
$lines[] = Html::a($label, $url, array_merge($this->linkOptions, $linkOptions));
$lines[] = Html::a($label, $url, array_merge($this->linkOptions, $linkOptions))
->encode($this->encodeLinks)
->render();

$dropdownWidget = self::widget()
->dividerClass($this->dividerClass)
Expand All @@ -367,18 +367,18 @@ private function renderItems(array $items, array $itemsOptions = []): string
}

return
Html::beginTag('div', $itemsOptions) . "\n" .
Html::openTag('div', $itemsOptions) . "\n" .
implode("\n", $lines) . "\n" .
Html::endTag('div');
Html::closeTag('div');
}

private function renderIcon(string $label, string $icon, array $iconOptions): string
{
if ($icon !== '') {
$label = Html::beginTag('span', $iconOptions) .
Html::tag('i', '', ['class' => $icon, 'encode' => false]) .
Html::endTag('span') .
Html::tag('span', $label, ['encode' => false]);
$label = Html::openTag('span', $iconOptions) .
Html::tag('i', '', ['class' => $icon])->encode(false) .
Html::closeTag('span') .
Html::span($label)->encode(false);
}

return $label;
Expand Down
26 changes: 14 additions & 12 deletions src/Menu.php
Expand Up @@ -356,7 +356,9 @@ private function renderItems(array $items): string
$lines[] = $item['label'];
}
} else {
$lines[] = Html::tag($tag, $menu, $options);
$lines[] = $tag === false
? $menu
: Html::tag($tag, $menu, $options)->encode($this->encodeLinks)->render();
}
}

Expand Down Expand Up @@ -442,9 +444,9 @@ private function renderIcon(string $icon, array $iconOptions): string
$html = '';

if ($icon !== '') {
$html = Html::beginTag('span', $iconOptions) .
$html = Html::openTag('span', $iconOptions) .
Html::tag('i', '', ['class' => $icon]) .
Html::endTag('span');
Html::closeTag('span');
}

return $html;
Expand All @@ -454,25 +456,25 @@ private function buildOptions(): void
{
$this->options = $this->addOptions($this->options, 'menu');
$this->itemsOptions = $this->addOptions($this->itemsOptions, 'menu-list');

if ($this->encodeLinks === false) {
$this->itemOptions['encode'] = false;
}
}

private function buildMenu(): string
{
$tag = ArrayHelper::remove($this->options, 'tag', 'ul');
$html = Html::beginTag('aside', $this->options) . "\n";
$html = Html::openTag('aside', $this->options) . "\n";

if ($this->brand !== '') {
$html .= $this->brand . "\n";
}

$html .= Html::beginTag($tag, $this->itemsOptions) . "\n";
$html .= $this->renderItems($this->items) . "\n";
$html .= Html::endTag($tag) . "\n";
$html .= Html::endTag('aside');
if ($tag) {
$html .= Html::openTag($tag, $this->itemsOptions);
}
$html .= "\n" . $this->renderItems($this->items) . "\n";
if ($tag) {
$html .= Html::closeTag($tag);
}
$html .= "\n" . Html::closeTag('aside');

return $html;
}
Expand Down
29 changes: 13 additions & 16 deletions src/Message.php
Expand Up @@ -37,12 +37,12 @@ protected function run(): string
$this->buildOptions();

return
Html::beginTag('div', $this->options) . "\n" .
$this->renderHeader() .
Html::beginTag('div', $this->bodyOptions) . "\n" .
$this->renderBodyEnd() . "\n" .
Html::endTag('div') . "\n" .
Html::endTag('div');
Html::openTag('div', $this->options) . "\n" .
$this->renderHeader() .
Html::openTag('div', $this->bodyOptions) . "\n" .
$this->renderBodyEnd() . "\n" .
Html::closeTag('div') . "\n" .
Html::closeTag('div');
}

/**
Expand Down Expand Up @@ -210,20 +210,15 @@ private function buildOptions(): void
$this->bodyOptions = $this->addOptions($this->bodyOptions, 'message-body');
$this->closeButtonOptions = $this->addOptions($this->closeButtonOptions, 'delete');
$this->headerOptions = $this->addOptions($this->headerOptions, 'message-header');

if ($this->encodeTags === false) {
$this->closeButtonOptions['encode'] = false;
$this->options['encode'] = false;
}
}

private function renderHeader(): string
{
$html = '';

if ($this->withoutHeader) {
$html = Html::beginTag('div', $this->headerOptions) . "\n" . $this->renderHeaderMessage() . "\n" .
Html::endTag('div') . "\n";
$html = Html::openTag('div', $this->headerOptions) . "\n" . $this->renderHeaderMessage() . "\n" .
Html::closeTag('div') . "\n";
}

return $html;
Expand Down Expand Up @@ -251,12 +246,12 @@ private function renderCloseButton(): ?string
return null;
}

$spanOptions = ['aria-hidden' => 'true', 'encode' => false];
$spanOptions = ['aria-hidden' => 'true'];
$tag = ArrayHelper::remove($this->closeButtonOptions, 'tag', 'button');
$label = ArrayHelper::remove(
$this->closeButtonOptions,
'label',
Html::tag('span', '×', $spanOptions)
Html::tag('span', '×', $spanOptions)->encode(false)->render()
);

if ($tag === 'button') {
Expand All @@ -267,6 +262,8 @@ private function renderCloseButton(): ?string
Html::addCssClass($this->closeButtonOptions, $this->size);
}

return Html::tag($tag, $label, $this->closeButtonOptions);
return Html::tag($tag, $label ?? '', $this->closeButtonOptions)
->encode($this->encodeTags)
->render();
}
}
12 changes: 6 additions & 6 deletions src/Modal.php
Expand Up @@ -69,19 +69,19 @@ public function begin(): ?string

$html = '';
$html .= $this->renderToggleButton() . "\n";
$html .= Html::beginTag('div', $this->options) . "\n"; // .modal
$html .= Html::openTag('div', $this->options) . "\n"; // .modal
$html .= Html::tag('div', '', ['class' => 'modal-background']) . "\n";
$html .= $this->renderCloseButton() . "\n";
$html .= Html::beginTag('div', $this->contentOptions) . "\n"; // .modal-content
$html .= Html::openTag('div', $this->contentOptions) . "\n"; // .modal-content

return $html;
}

protected function run(): string
{
$html = '';
$html .= Html::endTag('div') . "\n"; // .modal-content
$html .= Html::endTag('div'); // .modal
$html .= Html::closeTag('div') . "\n"; // .modal-content
$html .= Html::closeTag('div'); // .modal

return $html;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public function contentOptions(array $value): self
private function renderToggleButton(): string
{
if ($this->withoutToggleButton) {
return Html::button($this->toggleButtonLabel, $this->toggleButtonOptions);
return Html::button($this->toggleButtonLabel, $this->toggleButtonOptions)->render();
}

return '';
Expand All @@ -283,7 +283,7 @@ private function renderToggleButton(): string
private function renderCloseButton(): string
{
if ($this->withoutCloseButton) {
return Html::button('', $this->closeButtonOptions);
return Html::button('', $this->closeButtonOptions)->render();
}

return '';
Expand Down
24 changes: 12 additions & 12 deletions src/ModalCard.php
Expand Up @@ -80,9 +80,9 @@ public function begin(): ?string

$html = '';
$html .= $this->renderToggleButton() . "\n";
$html .= Html::beginTag('div', $this->options) . "\n"; // .modal
$html .= Html::openTag('div', $this->options) . "\n"; // .modal
$html .= $this->renderBackgroundTransparentOverlay() . "\n"; // .modal-background
$html .= Html::beginTag('div', $this->contentOptions) . "\n"; // .modal-card
$html .= Html::openTag('div', $this->contentOptions) . "\n"; // .modal-card
$html .= $this->renderHeader();
$html .= $this->renderBodyBegin() . "\n";

Expand All @@ -94,8 +94,8 @@ protected function run(): string
$html = '';
$html .= $this->renderBodyEnd() . "\n";
$html .= $this->renderFooter() . "\n";
$html .= Html::endTag('div') . "\n"; // .modal-card
$html .= Html::endTag('div'); // .modal
$html .= Html::closeTag('div') . "\n"; // .modal-card
$html .= Html::closeTag('div'); // .modal

return $html;
}
Expand Down Expand Up @@ -381,7 +381,7 @@ public function title(string $value): self
private function renderToggleButton(): string
{
if ($this->withoutToggleButton) {
return Html::button($this->toggleButtonLabel, $this->toggleButtonOptions);
return Html::button($this->toggleButtonLabel, $this->toggleButtonOptions)->render();
}

return '';
Expand All @@ -397,7 +397,7 @@ private function renderToggleButton(): string
private function renderCloseButton(): string
{
if ($this->withoutCloseButton) {
return Html::button('', $this->closeButtonOptions);
return Html::button('', $this->closeButtonOptions)->render();
}

return '';
Expand All @@ -413,10 +413,10 @@ private function renderCloseButton(): string
private function renderHeader(): string
{
$html = '';
$html .= Html::beginTag('header', $this->headerOptions) . "\n";
$html .= Html::openTag('header', $this->headerOptions) . "\n";
$html .= Html::tag('p', $this->title, $this->titleOptions) . "\n";
$html .= $this->renderCloseButton() . "\n";
$html .= Html::endTag('header') . "\n";
$html .= Html::closeTag('header') . "\n";

return $html;
}
Expand All @@ -430,7 +430,7 @@ private function renderHeader(): string
*/
private function renderBodyBegin(): string
{
return Html::beginTag('section', $this->bodyOptions);
return Html::openTag('section', $this->bodyOptions);
}

/**
Expand All @@ -442,7 +442,7 @@ private function renderBodyBegin(): string
*/
private function renderBodyEnd(): string
{
return Html::endTag('section');
return Html::closeTag('section');
}

/**
Expand All @@ -454,7 +454,7 @@ private function renderBodyEnd(): string
*/
private function renderFooter(): string
{
return Html::tag('footer', $this->footer, $this->footerOptions);
return Html::tag('footer', $this->footer, $this->footerOptions)->render();
}

/**
Expand All @@ -466,7 +466,7 @@ private function renderFooter(): string
*/
private function renderBackgroundTransparentOverlay(): string
{
return Html::tag('div', '', ['class' => 'modal-background']);
return Html::tag('div', '', ['class' => 'modal-background'])->render();
}

private function buildOptions(): void
Expand Down

0 comments on commit e002020

Please sign in to comment.