Skip to content

Commit

Permalink
FIX Correctly display config as its own section
Browse files Browse the repository at this point in the history
There was code there to do this already, but it seems like it just never
got finished.
  • Loading branch information
GuySartorelli committed Oct 11, 2023
1 parent c4ffeed commit 90fd858
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
38 changes: 38 additions & 0 deletions conf/themes/silverstripe/class.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,44 @@

{% endblock %}

{# This has to be included so that we can exclude config from the properties section #}
{% block properties %}
<table class="table table-condensed">
{% for property in properties %}
{# BEGIN CUSTOMISATION - exclude config properties #}
{% if not loop.parent.class.propertyIsConfig(property) %}
{# END CUSTOMISATION #}
<tr>
<td id="property_{{ property.name|raw }}">
{% if property.isStatic() %}static{% endif %}
{% if property.isProtected() %}protected{% endif %}
{% if property.isPrivate() %}private{% endif %}
{{ hint_link(property.hint) }}
{% if property.isInternal() %}<span class="label label-warning">{% trans 'internal' %}</span>{% endif %}
{% if property.isDeprecated() %}<span class="label label-danger">{% trans 'deprecated' %}</span>{% endif %}
{% if property.isReadOnly() %}<span class="label label-primary">{% trans 'read-only' %}</span>{% endif %}
{% if property.isWriteOnly() %}<span class="label label-success">{% trans 'write-only' %}</span>{% endif %}

{% if property.hasSince() %}
<i>{{ 'Since:'|trans }} {{ property.getSince() }}</i>
<br>
{% endif %}
</td>
<td>${{ property.name|raw }}</td>
<td class="last">{{ property.shortdesc|desc(class)|md_to_html }}</td>
<td>
{%- if property.class is not same as(class) -%}
<small>{{ 'from&nbsp;%s'|trans|format(property_link(property, false, true))|raw }}</small>
{%- endif -%}
</td>
</tr>
{# BEGIN CUSTOMISATION #}
{% endif %}
{# END CUSTOMISATION #}
{% endfor %}
</table>
{% endblock %}

{# BEGIN CUSTOMISATION - completely new block #}
{% block configs %}
<table class="table table-condensed">
Expand Down
27 changes: 24 additions & 3 deletions src/Reflection/SilverStripeClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,39 @@

class SilverStripeClassReflection extends ClassReflection
{

/** @var array<string,PropertyReflection> */
protected $configs = [];

public function addConfig(PropertyReflection $property): void
{
$this->configs[$property->getName()] = $property;
$property->setClass($this);
}

public function getConfigs(): array
public function getConfigs($deep = false): array
{
if (empty($this->configs) && $this->hasTrait('SilverStripe\Core\Config\Configurable')) {
foreach ($this->getProperties($deep) as $property) {
if ($this->propertyIsConfig($property)) {
$this->addConfig($property);
}
}
}
return $this->configs;
}

public function propertyIsConfig(PropertyReflection $property): bool
{
return !$property->isInternal() && $property->isStatic() && $property->isPrivate();
}

private function hasTrait(string $traitName): bool
{
$traits = $this->getTraits(true);
foreach ($traits as $trait) {
if ($trait->getName() === $traitName) {
return true;
}
}
return false;
}
}

0 comments on commit 90fd858

Please sign in to comment.