Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 160e368

Browse files
authored
Merge pull request #2285 from magento-trigger/MAGETWO-71571-link-ui-component
Implemented [Ui Component] URL Input: External Link
2 parents d3971c9 + aebe881 commit 160e368

File tree

22 files changed

+653
-3
lines changed

22 files changed

+653
-3
lines changed

app/code/Magento/Cms/Model/Wysiwyg/ConfigProviderFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Cms\Model\Wysiwyg;
710

811
/**
@@ -15,7 +18,7 @@ class ConfigProviderFactory
1518
*
1619
* @var \Magento\Framework\ObjectManagerInterface
1720
*/
18-
protected $objectManager;
21+
private $objectManager;
1922

2023
/**
2124
* @param \Magento\Framework\ObjectManagerInterface $objectManager
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Ui\Component\Form\Element;
10+
11+
/**
12+
* Url Input to process data for urlInput component
13+
*/
14+
class UrlInput extends \Magento\Ui\Component\Form\Element\AbstractElement
15+
{
16+
const NAME = 'urlInput';
17+
18+
/**
19+
* Get component name
20+
*
21+
* @return string
22+
*/
23+
public function getComponentName()
24+
{
25+
return static::NAME;
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function prepare()
32+
{
33+
$config = $this->getData('config');
34+
//process urlTypes
35+
if (isset($config['urlTypes'])) {
36+
$links = $config['urlTypes']->getConfig();
37+
$config['urlTypes'] = $links;
38+
}
39+
$this->setData('config', (array)$config);
40+
parent::prepare();
41+
}
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Ui\Model\UrlInput;
8+
9+
/**
10+
* Config interface for url link types
11+
*/
12+
interface ConfigInterface
13+
{
14+
/**
15+
* Returns config for url link type
16+
*
17+
* @return array
18+
*/
19+
public function getConfig();
20+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Ui\Model\UrlInput;
10+
11+
/**
12+
* Returns information about allowed links
13+
*/
14+
class LinksConfigProvider implements ConfigInterface
15+
{
16+
/**
17+
* @var array
18+
*/
19+
private $linksConfiguration;
20+
21+
/**
22+
* Object manager
23+
*
24+
* @var \Magento\Framework\ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* LinksProvider constructor.
30+
* @param array $linksConfiguration
31+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
32+
*/
33+
public function __construct(
34+
array $linksConfiguration,
35+
\Magento\Framework\ObjectManagerInterface $objectManager
36+
) {
37+
$this->linksConfiguration = $linksConfiguration;
38+
$this->objectManager = $objectManager;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function getConfig()
45+
{
46+
$config = [];
47+
foreach ($this->linksConfiguration as $linkName => $className) {
48+
$config[$linkName] = $this->createConfigProvider($className)->getConfig();
49+
}
50+
return $config;
51+
}
52+
53+
/**
54+
* Create config provider
55+
*
56+
* @param string $instance
57+
* @return ConfigInterface
58+
*/
59+
private function createConfigProvider($instance)
60+
{
61+
if (!is_subclass_of(
62+
$instance,
63+
ConfigInterface::class
64+
)
65+
) {
66+
throw new \InvalidArgumentException(
67+
$instance .
68+
' does not implement ' .
69+
ConfigInterface::class
70+
);
71+
}
72+
return $this->objectManager->create($instance);
73+
}
74+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Ui\Model\UrlInput;
9+
10+
/**
11+
* Returns configuration for default Url Input type
12+
*/
13+
class Url implements ConfigInterface
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function getConfig()
19+
{
20+
return [
21+
'label' => __('URL'),
22+
'component' => 'Magento_Ui/js/form/element/abstract',
23+
'template' => 'ui/form/element/input',
24+
'sortOrder' => 20,
25+
];
26+
}
27+
}

app/code/Magento/Ui/etc/adminhtml/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@
4444
</argument>
4545
</arguments>
4646
</type>
47+
<type name="Magento\Ui\Model\UrlInput\LinksConfigProvider">
48+
<arguments>
49+
<argument name="linksConfiguration" xsi:type="array">
50+
<item name="default" xsi:type="string">Magento\Ui\Model\UrlInput\Url</item>
51+
</argument>
52+
</arguments>
53+
</type>
4754
</config>

app/code/Magento/Ui/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@
416416
<item name="additionalClasses" xsi:type="object">Magento\Ui\Config\Converter\AdditionalClasses</item>
417417
<item name="options" xsi:type="object">Magento\Ui\Config\Converter\Options</item>
418418
<item name="actions" xsi:type="object">Magento\Ui\Config\Converter\Actions\Proxy</item>
419+
<item name="urlTypes" xsi:type="object">Magento\Ui\Config\Converter\Actions\Proxy</item>
419420
</argument>
420421
<argument name="discriminator" xsi:type="string">type</argument>
421422
</arguments>

app/code/Magento/Ui/etc/ui_components.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/email.xsd"/>
2929
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/exportButton.xsd"/>
3030
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/field.xsd"/>
31+
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/urlInput.xsd"/>
3132
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/fieldset.xsd"/>
3233
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/file.xsd"/>
3334
<xs:include schemaLocation="urn:magento:module:Magento_Ui:view/base/ui_component/etc/definition/fileUploader.xsd"/>

app/code/Magento/Ui/etc/ui_configuration.xsd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<xs:element ref="text" maxOccurs="unbounded"/>
5555
<xs:element ref="textarea" maxOccurs="unbounded"/>
5656
<xs:element ref="wysiwyg" maxOccurs="unbounded"/>
57+
<xs:element ref="urlInput" maxOccurs="unbounded"/>
5758
</xs:choice>
5859
</xs:group>
5960
<xs:group name="listingElements">
@@ -780,4 +781,12 @@
780781
</xs:documentation>
781782
</xs:annotation>
782783
</xs:element>
784+
<xs:element name="urlInput" type="componentUrlInput">
785+
<xs:annotation>
786+
<xs:documentation>
787+
The Url Input component allows to insert External URL and relative URL into the content. Add abilities
788+
to define custom url link types.
789+
</xs:documentation>
790+
</xs:annotation>
791+
</xs:element>
783792
</xs:schema>

app/code/Magento/Ui/etc/ui_definition.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<xs:element name="textarea" type="componentTextarea"/>
7676
<xs:element name="wysiwyg" type="componentWysiwyg"/>
7777
<xs:element name="inlineEditing" type="componentInlineEditing"/>
78+
<xs:element name="urlInput" type="componentUrlInput"/>
7879
</xs:choice>
7980
</xs:complexType>
8081
</xs:schema>

app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,22 @@
410410
<component name="hidden" include="abstractSettings"/>
411411
<component name="filterInput" include="abstractSettings"/>
412412
<component name="filterDate" include="abstractSettings"/>
413+
<!--add here list of required settings-->
414+
<component name="urlInput" include="abstractSettings">
415+
<schema name="current">
416+
<argument name="data" xsi:type="array">
417+
<item name="config" xsi:type="array">
418+
<!--selected related data-->
419+
<item name="urlTypes" type="urlTypes" xsi:type="converter">settings/urlTypes</item>
420+
<item name="isDisplayAdditionalSettings" type="boolean" xsi:type="xpath">settings/isDisplayAdditionalSettings</item>
421+
<item name="settingLabel" type="string" translate="true" xsi:type="xpath">settings/settingLabel</item>
422+
<item name="typeSelectorTemplate" type="string" translate="true" xsi:type="xpath">settings/typeSelectorTemplate</item>
423+
<item name="settingTemplate" type="string" translate="true" xsi:type="xpath">settings/settingTemplate</item>
424+
<item name="settingValue" type="boolean" xsi:type="xpath">settings/settingValue</item>
425+
</item>
426+
</argument>
427+
</schema>
428+
</component>
413429
<component name="fileUploader" include="abstractSettings">
414430
<schema name="current">
415431
<argument name="data" xsi:type="array">

app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@
149149
<initialMediaGalleryOpenSubpath>wysiwyg</initialMediaGalleryOpenSubpath>
150150
</settings>
151151
</imageUploader>
152+
<urlInput class="Magento\Ui\Component\Form\Element\UrlInput" component="Magento_Ui/js/form/element/url-input" template="ui/form/element/url-input">
153+
<settings>
154+
<settingTemplate>ui/form/element/urlInput/setting</settingTemplate>
155+
<typeSelectorTemplate>ui/form/element/urlInput/typeSelector</typeSelectorTemplate>
156+
<isDisplayAdditionalSettings>true</isDisplayAdditionalSettings>
157+
</settings>
158+
</urlInput>
152159
<!-- Form elements -->
153160

154161
<!-- Form element data types -->

app/code/Magento/Ui/view/base/ui_component/etc/definition/ui_settings.xsd

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@
219219
</xs:attribute>
220220
</xs:complexType>
221221

222+
<xs:complexType name="urlsType">
223+
<xs:annotation>
224+
<xs:documentation>
225+
The array of the configuration for urls types to be displayed in the list for selection.
226+
</xs:documentation>
227+
</xs:annotation>
228+
229+
</xs:complexType>
230+
222231
<xs:element name="param" type="argumentType"/>
223232

224233
<xs:element name="multiple" type="xs:boolean">
@@ -601,18 +610,33 @@
601610
</xs:choice>
602611
</xs:complexType>
603612

604-
<xs:complexType name="exportsType">
613+
<xs:complexType name="linksType">
605614
<xs:sequence minOccurs="0" maxOccurs="unbounded">
606615
<xs:element name="link" type="linkType"/>
607616
</xs:sequence>
608617
</xs:complexType>
609618

610-
<xs:complexType name="linksType">
619+
<xs:complexType name="exportsType">
611620
<xs:sequence minOccurs="0" maxOccurs="unbounded">
612621
<xs:element name="link" type="linkType"/>
613622
</xs:sequence>
614623
</xs:complexType>
615624

625+
<xs:complexType name="urlTypes">
626+
<xs:annotation>
627+
<xs:documentation>
628+
The array of the configuration for urls types to be displayed in the list for selection.
629+
</xs:documentation>
630+
</xs:annotation>
631+
<xs:attribute name="class" use="required" type="xs:string">
632+
<xs:annotation>
633+
<xs:documentation>
634+
Path to the PHP class that provides configuration.
635+
</xs:documentation>
636+
</xs:annotation>
637+
</xs:attribute>
638+
</xs:complexType>
639+
616640
<xs:complexType name="listensType">
617641
<xs:sequence minOccurs="0" maxOccurs="unbounded">
618642
<xs:element name="link" type="linkType"/>

0 commit comments

Comments
 (0)