Skip to content

Commit

Permalink
MAGETWO-89168: Develop UI component
Browse files Browse the repository at this point in the history
  • Loading branch information
irenelagno committed Mar 21, 2018
1 parent b032bbc commit 3a8cb88
Show file tree
Hide file tree
Showing 21 changed files with 597 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/code/Magento/Cms/Model/Wysiwyg/ConfigProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Cms\Model\Wysiwyg;

/**
Expand All @@ -15,7 +18,7 @@ class ConfigProviderFactory
*
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $objectManager;
private $objectManager;

/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager
Expand Down
42 changes: 42 additions & 0 deletions app/code/Magento/Ui/Component/Form/Element/UrlInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Ui\Component\Form\Element;

/**
* Url Input to process data for urlInput component
*/
class UrlInput extends \Magento\Ui\Component\Form\Element\AbstractElement
{
const NAME = 'urlInput';

/**
* Get component name
*
* @return string
*/
public function getComponentName()
{
return static::NAME;
}

/**
* {@inheritdoc}
*/
public function prepare()
{
$config = $this->getData('config');
//process urlTypes
if (isset($config['urlTypes'])) {
$links = $config['urlTypes']->getConfig();
$config['urlTypes'] = $links;
}
$this->setData('config', (array)$config);
parent::prepare();
}
}
20 changes: 20 additions & 0 deletions app/code/Magento/Ui/Model/UrlInput/ConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Ui\Model\UrlInput;

/**
* Config interface for url link types
*/
interface ConfigInterface
{
/**
* Returns config for url link type
*
* @return array
*/
public function getConfig();
}
28 changes: 28 additions & 0 deletions app/code/Magento/Ui/Model/UrlInput/DefaultLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Ui\Model\UrlInput;

/**
* Returns configuration for default Url Input type
*/
class DefaultLink implements ConfigInterface
{

/**
* {@inheritdoc}
*/
public function getConfig()
{
return [
'label' => __('URL'),
'component' => 'Magento_Ui/js/form/element/abstract',
'template' => 'ui/form/element/input',
'sortOrder' => 20,
];
}
}
74 changes: 74 additions & 0 deletions app/code/Magento/Ui/Model/UrlInput/LinksProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Ui\Model\UrlInput;

/**
* Returns information about allowed links
*/
class LinksProvider implements ConfigInterface
{
/**
* @var array
*/
private $linksConfiguration;

/**
* Object manager
*
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;

/**
* LinksProvider constructor.
* @param array $linksConfiguration
* @param \Magento\Framework\ObjectManagerInterface $objectManager
*/
public function __construct(
array $linksConfiguration,
\Magento\Framework\ObjectManagerInterface $objectManager
) {
$this->linksConfiguration = $linksConfiguration;
$this->objectManager = $objectManager;
}


public function getConfig()
{
$config = [];
foreach ($this->linksConfiguration as $linkName => $className)
{
$config[$linkName] = $this->createConfigProvider($className)->getConfig();
}
return $config;
}

/**
* Create config provider
*
* @param string $instance
* @return ConfigInterface
*/
private function createConfigProvider($instance)
{
if (!is_subclass_of(
$instance,
ConfigInterface::class
)
) {
throw new \InvalidArgumentException(
$instance .
' does not implement ' .
ConfigInterface::class
);
}
return $this->objectManager->create($instance);

}
}
7 changes: 7 additions & 0 deletions app/code/Magento/Ui/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@
</argument>
</arguments>
</type>
<type name="Magento\Ui\Model\UrlInput\LinksProvider">
<arguments>
<argument name="linksConfiguration" xsi:type="array">
<item name="default" xsi:type="string">Magento\Ui\Model\UrlInput\DefaultLink</item>
</argument>
</arguments>
</type>
</config>
1 change: 1 addition & 0 deletions app/code/Magento/Ui/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
<item name="additionalClasses" xsi:type="object">Magento\Ui\Config\Converter\AdditionalClasses</item>
<item name="options" xsi:type="object">Magento\Ui\Config\Converter\Options</item>
<item name="actions" xsi:type="object">Magento\Ui\Config\Converter\Actions\Proxy</item>
<item name="urlTypes" xsi:type="object">Magento\Ui\Config\Converter\Actions\Proxy</item>
</argument>
<argument name="discriminator" xsi:type="string">type</argument>
</arguments>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Ui/etc/ui_components.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/email.xsd"/>
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/exportButton.xsd"/>
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/field.xsd"/>
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/urlInput.xsd"/>
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/fieldset.xsd"/>
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/file.xsd"/>
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/fileUploader.xsd"/>
Expand Down
9 changes: 9 additions & 0 deletions app/code/Magento/Ui/etc/ui_configuration.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<xs:element ref="text" maxOccurs="unbounded"/>
<xs:element ref="textarea" maxOccurs="unbounded"/>
<xs:element ref="wysiwyg" maxOccurs="unbounded"/>
<xs:element ref="urlInput" maxOccurs="unbounded"/>
</xs:choice>
</xs:group>
<xs:group name="listingElements">
Expand Down Expand Up @@ -780,4 +781,12 @@
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="urlInput" type="componentUrlInput">
<xs:annotation>
<xs:documentation>
The Url Input component allows to insert External URL and relative URL into the content. Add abilities
to define custom url link types.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
1 change: 1 addition & 0 deletions app/code/Magento/Ui/etc/ui_definition.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<xs:element name="textarea" type="componentTextarea"/>
<xs:element name="wysiwyg" type="componentWysiwyg"/>
<xs:element name="inlineEditing" type="componentInlineEditing"/>
<xs:element name="urlInput" type="componentUrlInput"/>
</xs:choice>
</xs:complexType>
</xs:schema>
15 changes: 15 additions & 0 deletions app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,21 @@
<component name="hidden" include="abstractSettings"/>
<component name="filterInput" include="abstractSettings"/>
<component name="filterDate" include="abstractSettings"/>
<!--add here list of required settings-->
<component name="urlInput" include="abstractSettings">
<schema name="current">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!--selected related data-->
<item name="urlTypes" type="urlTypes" xsi:type="converter">settings/urlTypes</item>
<item name="isDisplayAdditionalSettings" type="boolean" xsi:type="xpath">settings/isDisplayAdditionalSettings</item>
<item name="settingLabel" type="string" translate="true" xsi:type="xpath">settings/settingLabel</item>
<item name="typeSelectorTemplate" type="string" translate="true" xsi:type="xpath">settings/typeSelectorTemplate</item>
<item name="settingTemplate" type="string" translate="true" xsi:type="xpath">settings/settingTemplate</item>
</item>
</argument>
</schema>
</component>
<component name="fileUploader" include="abstractSettings">
<schema name="current">
<argument name="data" xsi:type="array">
Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Ui/view/base/ui_component/etc/definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@
<range class="Magento\Ui\Component\Form\Element\Range" component="Magento_Ui/js/grid/filters/range"/>
<fileUploader class="Magento\Ui\Component\Form\Element\DataType\Media" component="Magento_Ui/js/form/element/file-uploader" template="ui/form/element/uploader/uploader"/>
<imageUploader class="Magento\Ui\Component\Form\Element\DataType\Media\Image" component="Magento_Ui/js/form/element/image-uploader" template="ui/form/element/uploader/image"/>
<urlInput class="Magento\Ui\Component\Form\Element\UrlInput" component="Magento_Ui/js/form/element/url-input" template="ui/form/element/url-input">
<settings>
<settingTemplate>ui/form/element/urlInput/setting</settingTemplate>
<typeSelectorTemplate>ui/form/element/urlInput/typeSelector</typeSelectorTemplate>
<isDisplayAdditionalSettings>true</isDisplayAdditionalSettings>
</settings>
</urlInput>
<!-- Form elements -->

<!-- Form element data types -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@
</xs:attribute>
</xs:complexType>

<xs:complexType name="urlsType">
<xs:annotation>
<xs:documentation>
The array of the configuration for urls types to be displayed in the list for selection.
</xs:documentation>
</xs:annotation>

</xs:complexType>

<xs:element name="param" type="argumentType"/>

<xs:element name="multiple" type="xs:boolean">
Expand Down Expand Up @@ -607,10 +616,19 @@
</xs:sequence>
</xs:complexType>

<xs:complexType name="linksType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="link" type="linkType"/>
</xs:sequence>
<xs:complexType name="urlTypes">
<xs:annotation>
<xs:documentation>
The array of the configuration for urls types to be displayed in the list for selection.
</xs:documentation>
</xs:annotation>
<xs:attribute name="class" use="required" type="xs:string">
<xs:annotation>
<xs:documentation>
Path to the PHP class that provides configuration.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>

<xs:complexType name="listensType">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<!-- Include section -->
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/ui_component.xsd"/>

<xs:complexType name="componentUrlInput">
<xs:sequence>
<xs:group ref="configurable" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="settings" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="componentUrlInputSettings"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attributeGroup ref="ui_element_attributes"/>
</xs:complexType>

<xs:group name="componentUrlInputSettings">
<xs:choice>
<xs:group ref="abstractSettings"/>
<xs:element ref="scopeLabel"/>
<xs:element name="urlTypes" type="urlTypes">
<xs:annotation>
<xs:documentation>
Options for "urlInput" element
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="settingTemplate" type="xs:string">
<xs:annotation>
<xs:documentation>
The path to the custom url setting ".html" template.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="typeSelectorTemplate" type="xs:string">
<xs:annotation>
<xs:documentation>
The path to the custom url types selector ".html" template.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="settingLabel" type="translatableString">
<xs:annotation>
<xs:documentation>
The label for custom url setting.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="isDisplayAdditionalSettings" type="xs:boolean">
<xs:annotation>
<xs:documentation>
Allows to specify if display additional settings
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:choice>
</xs:group>
</xs:schema>
Loading

0 comments on commit 3a8cb88

Please sign in to comment.