Skip to content

Commit

Permalink
WIP rebase original debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 26, 2023
1 parent 4bb4c3d commit 2ae3b92
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/AccordionSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ protected function renderView(): void
if ($this->virtualPage) {
$this->template->set('itemId', $this->virtualPage->name);
$this->template->set('path', $this->virtualPage->getJsUrl('cut'));
} else {
// TODO hack to prevent rendering 'id=""'
$this->template->set('itemId', $this->name . '-vp-unused');
}
}
}
3 changes: 0 additions & 3 deletions src/Lister.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ protected function renderView(): void
return;
}

// Generate template for data row
$this->tRow->trySet('_id', $this->name);

// Iterate data rows
$this->_renderedRowsCount = 0;

Expand Down
92 changes: 70 additions & 22 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,46 +556,94 @@ public function stickyGet(string $name, string $newValue = null): ?string
*/
protected function renderView(): void
{
if ($this->class !== []) {
$this->template->append('class', implode(' ', $this->class));
if ($this->element !== 'div') {
$this->template->set('_element', $this->element);
} else {
$this->template->trySet('_element', $this->element);
}

if ($this->style !== []) {
$styles = [];
foreach ($this->style as $k => $v) {
$styles[] = $k . ': ' . $v . ';';
$app = $this->getApp();
if (!$app->isVoidTag($this->element)) {
$this->template->tryDangerouslySetHtml('_element_end_html', '</' . $this->element . '>');
}

$attrsHtml = [];

if ($this->name) {
$attrsHtml[] = 'id="' . $app->encodeHtml($this->name) . '"';

// TODO hack for template/tabs.html
if ($this->template->hasTag('Tabs')) {
array_pop($attrsHtml);
}
$this->template->append('style', implode(' ', $styles));

// TODO hack for template/form/control/upload.html
if ($this->template->hasTag('AfterBeforeInput') && str_contains($this->template->renderToHtml(), ' type="file"')) {
array_pop($attrsHtml);
}

// needed for template like '<input id="{$_id}_input">'
$this->template->trySet('_id', $this->name);
}

$class = null;
if ($this->class !== []) {
$class = implode(' ', $this->class);

// TODO remove once migrated
$this->template->tryAppend('class', implode(' ', $this->class));
}
if ($this->ui !== false && $this->ui !== '') {
$class = 'ui ' . $this->ui . ($class !== null ? ' ' . $class : '');
}
if ($class !== null) {
$attrsHtml[] = 'class="' . $app->encodeHtml($class) . '"';
}

// TODO remove once migrated
if ($this->ui) {
if (is_string($this->ui)) {
$this->template->set('_class', $this->ui);
$this->template->trySet('_class', $this->ui);
}
} else {
$this->template->tryDel('_ui');
}

if ($this->name) {
$this->template->trySet('_id', $this->name);
}
if ($this->style !== []) {
$styles = [];
foreach ($this->style as $k => $v) {
$styles[] = $k . ': ' . $app->encodeHtml($v) . ';';
}
$attrsHtml[] = 'style="' . implode(' ', $styles) . '"';

if ($this->element !== 'div') {
$this->template->set('_element', $this->element);
} else {
$this->template->trySet('_element', $this->element);
// TODO remove once migrated
$this->template->tryDangerouslyAppendHtml('style', implode(' ', $styles));
}

if (!$this->getApp()->isVoidTag($this->element)) {
$this->template->tryDangerouslySetHtml('_element_end_html', '</' . $this->element . '>');
foreach ($this->attr as $k => $v) {
$attrsHtml[] = $k . '="' . $app->encodeHtml((string) $v) . '"';
}

if ($this->attr !== []) {
$attrs = [];
foreach ($this->attr as $k => $v) {
$attrs[] = $k . '="' . $this->getApp()->encodeHtml((string) $v) . '"';
if ($attrsHtml !== []) {
try {
$this->template->dangerouslySetHtml('attributes', implode(' ', $attrsHtml));
} catch (Exception $e) {
// TODO this is a hack to ignore missing '{$attributes}' in core layout templates and should be removed
$template = $this->template;
$templateTags = array_map(fn () => true, array_diff_key(\Closure::bind(fn () => $template->tagTrees, null, HtmlTemplate::class)(), [HtmlTemplate::TOP_TAG => true]));
$isCoreLayoutTemplate = isset($templateTags['InitJsBundle']) // template/html.html
|| isset($templateTags['CssVisibility']) // template/layout/admin.html
|| isset($templateTags['BeforeHeaderContent']) // template/layout/centered.html
|| isset($templateTags['Buttons']) // template/form/layout/generic.html
|| isset($templateTags['footNominal']) // demos/layout/templates/layout1.html
|| isset($templateTags['atk_fp_country__name']) // collection/lister-ipp.php, interactive/scroll-container.php, interactive/scroll-lister.php
|| $templateTags === [] // form-control/input2.php
|| $templateTags === ['tag1' => true, 'tag2' => true] // basic/button.php
|| $templateTags === ['list' => true]; // Atk4\Ui\Tests\ListerTest::testListerRender2
if (!$isCoreLayoutTemplate) {
throw $e;
}
}
$this->template->dangerouslySetHtml('attributes', implode(' ', $attrs));
}
}

Expand Down

0 comments on commit 2ae3b92

Please sign in to comment.