*/ protected array $markups; protected Html $html; protected FieldMarkup $fieldMarkup; protected DataVendors $dataVendors; public function __construct(Html $html, FieldMarkup $fieldMarkup, DataVendors $dataVendors) { $this->html = $html; $this->fieldMarkup = $fieldMarkup; $this->dataVendors = $dataVendors; $this->markups = []; } protected function getRowMarkup(ViewData $acfViewData, FieldMetaInterface $fieldMeta, ItemData $item): string { if (!$fieldMeta->isFieldExist()) { return ''; } $fieldId = $item->field->getTwigFieldId(); $fieldType = $fieldMeta->getType(); $orCondition = $item->field->isVisibleWhenEmpty || $this->dataVendors->isEmptyValueSupportedInMarkup($item->field->getVendorName(), $fieldType) ? ' or true' : ''; $rowTabsNumber = 2; $rowType = 'row'; if ($this->dataVendors->isFieldTypeWithSubFields($fieldMeta->getVendorName(), $fieldMeta->getType())) { $rowType = $fieldType; } return sprintf("\r\n\t{%% if %s.value%s %%}\r\n", esc_html($fieldId), $orCondition) . $this->fieldMarkup->getRowMarkup( $rowType, '', $acfViewData, $item, $item->field, $fieldMeta, $rowTabsNumber, $fieldId ) . "\t{% endif %}\r\n\r\n"; } protected function getMarkupFromCache(ViewData $view, bool $isSkipCache): string { $shortUniqueId = $view->getUniqueId(true); if (key_exists($shortUniqueId, $this->markups) && !$isSkipCache) { return $this->markups[$shortUniqueId]; } $content = ''; foreach ($view->items as $item) { $content .= $this->getRowMarkup( $view, $item->field->getFieldMeta(), $item ); } return $this->html->view($content, $view->getBemName(), $view->getTagName()); } public function getMarkup( ViewData $view, int $pageId, string $viewMarkup = '', bool $isSkipCache = false, bool $isIgnoreCustomMarkup = false ): string { $viewMarkup = ('' !== $viewMarkup || $isIgnoreCustomMarkup) ? $viewMarkup : trim($view->customMarkup); $viewMarkup = '' !== $viewMarkup ? $viewMarkup : $this->getMarkupFromCache($view, $isSkipCache); $this->markups[$view->getUniqueId(true)] = $viewMarkup; return $viewMarkup; } }