Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* use localized controls keys #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion behaviors/IndexModelFormOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ protected function getAddDatabaseFieldsDataTableConfig()
{
// Get all registered controls and build an array that uses the control types as key and value for each entry.
$controls = ControlLibrary::instance()->listControls();
$fieldTypes = array_merge(array_keys($controls['Standard']), array_keys($controls['Widgets']));
$fieldTypes = array_merge(
array_keys($controls[ControlLibrary::GROUP_STANDARD]['controls']),
array_keys($controls[ControlLibrary::GROUP_WIDGETS]['controls'])
);
$options = array_combine($fieldTypes, $fieldTypes);

return [
Expand Down
22 changes: 13 additions & 9 deletions classes/ControlLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use Event;
use Lang;
use Winter\Builder\Behaviors\IndexModelFormOperations;
use Winter\Builder\FormWidgets\FormBuilder;

/**
* Manages Builder form control library.
Expand Down Expand Up @@ -32,21 +34,23 @@ public function listControls($returnGrouped = true)
return $returnGrouped ? $this->groupedControls : $this->controls;
}

$this->groupedControls = [
$this->resolveControlGroupName(self::GROUP_STANDARD) => [],
$this->resolveControlGroupName(self::GROUP_WIDGETS) => []
];
/**
* @see FormBuilder::onModelFormLoadControlPalette
* @see IndexModelFormOperations::getAddDatabaseFieldsDataTableConfig
*/
$this->groupedControls = [];

Event::fire('pages.builder.registerControls', [$this]);

foreach ($this->controls as $controlType => $controlInfo) {
$controlGroup = $this->resolveControlGroupName($controlInfo['group']);

if (!array_key_exists($controlGroup, $this->groupedControls)) {
$this->groupedControls[$controlGroup] = [];
if (!array_key_exists($controlInfo['group'], $this->groupedControls)) {
$this->groupedControls[$controlInfo['group']] = [
'label' => $this->resolveControlGroupName($controlInfo['group']),
'controls' => []
];
}

$this->groupedControls[$controlGroup][$controlType] = $controlInfo;
$this->groupedControls[$controlInfo['group']]['controls'][$controlType] = $controlInfo;
}

return $returnGrouped ? $this->groupedControls : $this->controls;
Expand Down
5 changes: 2 additions & 3 deletions formwidgets/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ public function onModelFormLoadControlPalette()
$controlId = Input::get('controlId');

$library = ControlLibrary::instance();
$controls = $library->listControls();
$this->vars['registeredControls'] = $controls;
$this->vars['controlGroups'] = array_keys($controls);

$this->vars['controlsGroups'] = $library->listControls();

return [
'markup' => $this->makePartial('controlpalette'),
Expand Down
8 changes: 4 additions & 4 deletions formwidgets/formbuilder/partials/_controlpalette.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

<div class="control-filelist filelist-hero" data-control="filelist">
<ul>
<?php foreach ($controlGroups as $index=>$group): ?>
<?php foreach ($controlsGroups as $index=>$group): ?>
<li class="separator">
<h5><?= e($group) ?></h5>
<h5><?= e($group['label']) ?></h5>
</li>

<?php foreach ($registeredControls[$group] as $controlCode=>$controlInfo): ?>
<?php foreach ($group['controls'] as $controlCode=>$controlInfo): ?>
<li>
<a href="javascript:;"
data-builder-control-palette-control="<?= e($controlCode) ?>"
Expand All @@ -30,4 +30,4 @@ <h5><?= e($group) ?></h5>
</div>

</div>
</div>
</div>