2014-05-14 23:24:20 +10:00
|
|
|
<?php namespace Cms\FormWidgets;
|
|
|
|
|
|
|
|
use Backend\Classes\FormWidgetBase;
|
|
|
|
use Cms\Classes\ComponentManager;
|
|
|
|
use Cms\Classes\ComponentHelpers;
|
2020-04-04 18:02:43 +01:00
|
|
|
use Cms\Components\SoftComponent;
|
2017-03-16 07:00:39 +11:00
|
|
|
use Cms\Components\UnknownComponent;
|
2014-06-26 17:09:25 +11:00
|
|
|
use Exception;
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component Builder
|
|
|
|
* Builds a collection of Cms components and configures them.
|
|
|
|
*
|
2021-03-10 15:02:53 -06:00
|
|
|
* @package winter\wn-cms-module
|
2014-05-14 23:24:20 +10:00
|
|
|
* @author Alexey Bobkov, Samuel Georges
|
|
|
|
*/
|
|
|
|
class Components extends FormWidgetBase
|
|
|
|
{
|
|
|
|
/**
|
2017-03-16 06:26:14 +11:00
|
|
|
* @inheritDoc
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
$components = $this->listComponents();
|
|
|
|
|
2014-09-17 19:49:42 +10:00
|
|
|
return $this->makePartial('formcomponents', ['components' => $components]);
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function listComponents()
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
|
2014-10-11 01:29:22 +02:00
|
|
|
if (!isset($this->model->settings['components'])) {
|
2014-05-14 23:24:20 +10:00
|
|
|
return $result;
|
2014-10-11 01:29:22 +02:00
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
$manager->listComponents();
|
2014-11-01 12:00:45 +11:00
|
|
|
|
2014-09-17 19:49:42 +10:00
|
|
|
foreach ($this->model->settings['components'] as $name => $properties) {
|
2014-05-14 23:24:20 +10:00
|
|
|
list($name, $alias) = strpos($name, ' ') ? explode(' ', $name) : [$name, $name];
|
|
|
|
|
2014-06-26 17:09:25 +11:00
|
|
|
try {
|
|
|
|
$componentObj = $manager->makeComponent($name, null, $properties);
|
2020-04-04 18:02:43 +01:00
|
|
|
$componentObj->alias = ((starts_with($name, '@') && $alias !== $name) ? '@' : '') . $alias;
|
2014-06-26 17:09:25 +11:00
|
|
|
$componentObj->pluginIcon = 'icon-puzzle-piece';
|
|
|
|
|
2014-10-11 10:37:48 +11:00
|
|
|
/*
|
|
|
|
* Look up the plugin hosting this component
|
|
|
|
*/
|
2014-06-26 17:09:25 +11:00
|
|
|
$plugin = $manager->findComponentPlugin($componentObj);
|
|
|
|
if ($plugin) {
|
|
|
|
$pluginDetails = $plugin->pluginDetails();
|
2014-10-11 01:29:22 +02:00
|
|
|
if (isset($pluginDetails['icon'])) {
|
2014-06-26 17:09:25 +11:00
|
|
|
$componentObj->pluginIcon = $pluginDetails['icon'];
|
2014-10-11 01:29:22 +02:00
|
|
|
}
|
2014-06-26 17:09:25 +11:00
|
|
|
}
|
2014-11-01 12:00:45 +11:00
|
|
|
}
|
|
|
|
catch (Exception $ex) {
|
2020-04-04 18:02:43 +01:00
|
|
|
if (starts_with($name, '@')) {
|
|
|
|
$componentObj = new SoftComponent($properties);
|
|
|
|
$componentObj->name = $name;
|
|
|
|
$componentObj->alias = (($alias !== $name) ? '@' : '') . $alias;
|
|
|
|
$componentObj->pluginIcon = 'icon-flag';
|
|
|
|
} else {
|
|
|
|
$componentObj = new UnknownComponent(null, $properties, $ex->getMessage());
|
|
|
|
$componentObj->alias = $alias;
|
|
|
|
$componentObj->pluginIcon = 'icon-bug';
|
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
$result[] = $componentObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getComponentName($component)
|
|
|
|
{
|
|
|
|
return ComponentHelpers::getComponentName($component);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getComponentDescription($component)
|
|
|
|
{
|
|
|
|
return ComponentHelpers::getComponentDescription($component);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getComponentsPropertyConfig($component)
|
|
|
|
{
|
|
|
|
return ComponentHelpers::getComponentsPropertyConfig($component);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getComponentPropertyValues($component)
|
|
|
|
{
|
|
|
|
return ComponentHelpers::getComponentPropertyValues($component);
|
|
|
|
}
|
2014-10-11 01:29:22 +02:00
|
|
|
}
|