diff --git a/modules/cms/assets/css/october.components.css b/modules/cms/assets/css/october.components.css index 121845084..b4994db8c 100644 --- a/modules/cms/assets/css/october.components.css +++ b/modules/cms/assets/css/october.components.css @@ -118,6 +118,15 @@ div.control-componentlist.has-components { div.control-componentlist div.layout { width: auto; } +div.control-componentlist div.components div.layout-cell.error-component { + background: #ab2a1c; +} +div.control-componentlist div.components div.layout-cell.error-component > div { + color: #ffffff; +} +div.control-componentlist div.components div.layout-cell.error-component > div:after { + color: #ab2a1c; +} div.control-componentlist div.components div.layout-cell:first-child { border-bottom-left-radius: 3px; border-top-left-radius: 3px; diff --git a/modules/cms/assets/js/october.cmspage.js b/modules/cms/assets/js/october.cmspage.js index e2da4b975..bf14df02b 100644 --- a/modules/cms/assets/js/october.cmspage.js +++ b/modules/cms/assets/js/october.cmspage.js @@ -87,6 +87,18 @@ setPageTitle('') }) + /* + * Listen for the onBeforeRequest event + */ + $('#cms-master-tabs').on('oc.beforeRequest', function(event) { + var $form = $(event.target) + + if ( $('.components .layout-cell.error-component', $form).length > 0) { + if (!confirm('The form contains unknown components. Their properties will be lost on save. Do you want to save the form?')) + event.preventDefault() + } + }) + /* * Listen for the tabs "shown" event to track the current template in the list */ diff --git a/modules/cms/assets/less/october.components.less b/modules/cms/assets/less/october.components.less index 3c8c888ca..40589f41d 100644 --- a/modules/cms/assets/less/october.components.less +++ b/modules/cms/assets/less/october.components.less @@ -11,6 +11,8 @@ @color-component-hover-text: #ffffff; @color-component-placeholder: #e0e0e0; @color-group-bg: #f1f3f4; +@color-error-component-bg: #ab2a1c; +@color-error-component-text: #ffffff; .component-lego-icon() { position: absolute; @@ -117,6 +119,18 @@ div.control-componentlist { div.components { div.layout-cell { + &.error-component { + background: @color-error-component-bg; + + > div { + color: @color-error-component-text; + + &:after { + color: @color-error-component-bg; + } + } + } + &:first-child { .border-left-radius(3px); } diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index e5af60ff5..c37c46d7f 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -133,8 +133,8 @@ class CmsCompoundObject extends CmsObject $settingParts = explode(' ', $setting); $settingName = $settingParts[0]; - if (!$manager->hasComponent($settingName)) - continue; + // if (!$manager->hasComponent($settingName)) + // continue; $components[$setting] = $value; unset($this->settings[$setting]); diff --git a/modules/cms/classes/ComponentBase.php b/modules/cms/classes/ComponentBase.php index 2a37180d6..7e6d38eed 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -39,6 +39,18 @@ abstract class ComponentBase extends Extendable */ public $pluginIcon; + /** + * @var string Component CSS class name for the back-end page/layout component list. + * This field is used by the CMS internally. + */ + public $componentCssClass; + + /** + * @var boolean Determines whether Inspector can be used with the component. + * This field is used by the CMS internally. + */ + public $inspectorEnabled = true; + /** * @var string Specifies the component directory name. */ diff --git a/modules/cms/classes/ComponentManager.php b/modules/cms/classes/ComponentManager.php index 76168cfd8..8674c7a33 100644 --- a/modules/cms/classes/ComponentManager.php +++ b/modules/cms/classes/ComponentManager.php @@ -3,6 +3,7 @@ use Str; use Illuminate\Container\Container; use System\Classes\PluginManager; +use System\Classes\SystemException; /** * Component manager @@ -179,10 +180,10 @@ class ComponentManager { $className = $this->resolve($name); if (!$className) - return null; + throw new SystemException(sprintf('Class name is not registered for the component %s. Check the component plugin.', $name)); if (!class_exists($className)) - throw new \Exception('Component class not found '.$className); + throw new SystemException(sprintf('Component class not found %s.Check the component plugin.', $className)); $component = new $className($cmsObject, $properties); $component->name = $name; diff --git a/modules/cms/classes/UnknownComponent.php b/modules/cms/classes/UnknownComponent.php new file mode 100644 index 000000000..5d9c9c5ed --- /dev/null +++ b/modules/cms/classes/UnknownComponent.php @@ -0,0 +1,29 @@ +errorMessage = $errorMessage; + $this->componentCssClass = 'error-component'; + $this->inspectorEnabled = false; + + parent::__construct($cmsObject, $properties); + } + + public function componentDetails() + { + return [ + 'name' => 'Uknown component', + 'description' => $this->errorMessage + ]; + } +} \ No newline at end of file diff --git a/modules/cms/formwidgets/Components.php b/modules/cms/formwidgets/Components.php index 483831191..b52df6785 100644 --- a/modules/cms/formwidgets/Components.php +++ b/modules/cms/formwidgets/Components.php @@ -3,7 +3,9 @@ use Backend\Classes\FormWidgetBase; use Cms\Classes\ComponentManager; use Cms\Classes\ComponentHelpers; +use Cms\Classes\UnknownComponent; use Lang; +use Exception; /** * Component Builder @@ -36,15 +38,22 @@ class Components extends FormWidgetBase foreach ($this->model->settings['components'] as $name=>$properties) { list($name, $alias) = strpos($name, ' ') ? explode(' ', $name) : [$name, $name]; - $componentObj = $manager->makeComponent($name, null, $properties); - $componentObj->alias = $alias; - $componentObj->pluginIcon = 'icon-puzzle-piece'; + try { + $componentObj = $manager->makeComponent($name, null, $properties); - $plugin = $manager->findComponentPlugin($componentObj); - if ($plugin) { - $pluginDetails = $plugin->pluginDetails(); - if (isset($pluginDetails['icon'])) - $componentObj->pluginIcon = $pluginDetails['icon']; + $componentObj->alias = $alias; + $componentObj->pluginIcon = 'icon-puzzle-piece'; + + $plugin = $manager->findComponentPlugin($componentObj); + if ($plugin) { + $pluginDetails = $plugin->pluginDetails(); + if (isset($pluginDetails['icon'])) + $componentObj->pluginIcon = $pluginDetails['icon']; + } + } catch (Exception $ex) { + $componentObj = new UnknownComponent(null, $properties, $ex->getMessage()); + $componentObj->alias = $alias; + $componentObj->pluginIcon = 'icon-bug'; } $result[] = $componentObj; diff --git a/modules/cms/formwidgets/components/partials/_formcomponents.htm b/modules/cms/formwidgets/components/partials/_formcomponents.htm index e065303b1..0c769d9cd 100644 --- a/modules/cms/formwidgets/components/partials/_formcomponents.htm +++ b/modules/cms/formwidgets/components/partials/_formcomponents.htm @@ -2,15 +2,21 @@