Optimized logic for source.html.twig

This commit is contained in:
Kevin Frantz 2019-02-18 22:58:42 +01:00
parent c702ddf211
commit 15f9925e66
4 changed files with 62 additions and 43 deletions

View File

@ -9,6 +9,11 @@ use Infinito\Domain\RequestManagement\Action\RequestedActionServiceInterface;
*/ */
class TemplateNameService implements TemplateNameServiceInterface class TemplateNameService implements TemplateNameServiceInterface
{ {
/**
* @var unknown
*/
const BASE_TEMPLATE_DIR = __DIR__.'/../../../templates/';
/** /**
* @var string The namespace which should be ignored * @var string The namespace which should be ignored
*/ */
@ -71,7 +76,7 @@ class TemplateNameService implements TemplateNameServiceInterface
$origineClass = $this->getClass(); $origineClass = $this->getClass();
$baseReplaced = str_replace(self::BASE_NAMESPACE, self::BASE_ENTITY_TEMPLATE_FOLDER, $origineClass); $baseReplaced = str_replace(self::BASE_NAMESPACE, self::BASE_ENTITY_TEMPLATE_FOLDER, $origineClass);
$elements = explode('\\', $baseReplaced); $elements = explode('\\', $baseReplaced);
array_pop($elements); //Removes class name array_pop($elements); // Removes class name
$templatePath = implode('/', $elements); $templatePath = implode('/', $elements);
$lowerCasePath = strtolower($templatePath); $lowerCasePath = strtolower($templatePath);
@ -130,4 +135,29 @@ class TemplateNameService implements TemplateNameServiceInterface
{ {
return $this->getTemplatePath(self::MOLECULE_PRAEFFIX); return $this->getTemplatePath(self::MOLECULE_PRAEFFIX);
} }
private function templateExists(string $template): bool
{
return file_exists(self::BASE_TEMPLATE_DIR.$template);
}
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TemplateManagement\TemplateNameServiceInterface::doesAtomTemplateExists()
*/
public function doesAtomTemplateExist(): bool
{
return $this->templateExists($this->getAtomTemplateName());
}
/**
* {@inheritdoc}
*
* @see \Infinito\Domain\TemplateManagement\TemplateNameServiceInterface::doesMoleculeTemplateExists()
*/
public function doesMoleculeTemplateExist(): bool
{
return $this->templateExists($this->getMoleculeTemplateName());
}
} }

View File

@ -16,4 +16,14 @@ interface TemplateNameServiceInterface
* @return string a template without a frame * @return string a template without a frame
*/ */
public function getAtomTemplateName(): string; public function getAtomTemplateName(): string;
/**
* @return bool True if template exists
*/
public function doesAtomTemplateExist(): bool;
/**
* @return bool True if template exists
*/
public function doesMoleculeTemplateExist(): bool;
} }

View File

@ -0,0 +1 @@
{{ entity.text }}

View File

@ -8,52 +8,30 @@
</h1> </h1>
<div id="accordion"> <div id="accordion">
{% for action in layer_action_map.getActions('source') %} {% for action in layer_action_map.getActions('source') %}
<div class="card"> {{ action_template_name_service.setActionType(action) }}
<div class="card-header" id="heading_{{ action }}"> {% if action_template_name_service.doesAtomTemplateExist() %}
<h5 class="mb-0"> <div class="card">
<button class="btn btn-link collapsed" data-toggle="collapse" <div class="card-header" id="heading_{{ action }}">
data-target="#collapse_{{ action }}" aria-expanded="false" <h5 class="mb-0">
aria-controls="collapse_{{ action }}"> <button class="btn btn-link collapsed" data-toggle="collapse"
<i class="{{ action_icon_class_map.getIconClass(action) }}"></i> {{ action|trans }} data-target="#collapse_{{ action }}" aria-expanded="false"
</button> aria-controls="collapse_{{ action }}">
</h5> <i class="{{ action_icon_class_map.getIconClass(action) }}"></i> {{ action|trans }}
</div> </button>
<div id="collapse_{{ action }}" class="collapse" </h5>
aria-labelledby="heading_{{ action }}" data-parent="#accordion"> </div>
<div class="card-body">Anim pariatur cliche reprehenderit, enim <div id="collapse_{{ action }}" class="collapse"
eiusmod high life accusamus terry richardson ad squid. 3 wolf moon aria-labelledby="heading_{{ action }}" data-parent="#accordion">
officia aute, non cupidatat skateboard dolor brunch. Food truck <div class="card-body">
quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt {% include action_template_name_service.getAtomTemplateName() %}
aliqua put a bird on it squid single-origin coffee nulla assumenda </div>
shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes </div>
anderson cred nesciunt sapiente ea proident. Ad vegan excepteur </div>
butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw {% endif %}
denim aesthetic synth nesciunt you probably haven't heard of them
accusamus labore sustainable VHS.</div>
</div>
</div>
{% endfor %} {% endfor %}
</div> </div>
<hr /> <hr />
<div id="accordion"> <div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="true"
aria-controls="collapseOne">
<i class="fas fa-glasses"></i> Read
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show"
aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
{{ entity.text }}
</div>
</div>
</div>
<div class="card"> <div class="card">
<div class="card-header" id="headingThree"> <div class="card-header" id="headingThree">
<h5 class="mb-0"> <h5 class="mb-0">