Skip to content

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>

0 commit comments

Comments
 (0)