Skip to content

Commit 5dd8221

Browse files
committed
MAGETWO-65470: The visibility conditions improvements
docblocks
1 parent 41a1614 commit 5dd8221

File tree

4 files changed

+40
-35
lines changed

4 files changed

+40
-35
lines changed

lib/internal/Magento/Framework/View/Layout/AclCondition.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@
88
use Magento\Framework\View\Layout\Condition\VisibilityConditionInterface;
99

1010
/**
11-
* Class AclCondition.
11+
* Check that user is allowed to watch resource with given acl resource..
1212
*/
1313
class AclCondition implements VisibilityConditionInterface
1414
{
15+
/**
16+
* Unique name.
17+
*/
18+
const NAME = 'acl';
19+
1520
/**
1621
* @var \Magento\Framework\AuthorizationInterface
1722
*/
1823
private $authorization;
1924

2025
/**
21-
* AclCondition constructor.
22-
*
2326
* @param \Magento\Framework\AuthorizationInterface $authorization
2427
*/
2528
public function __construct(\Magento\Framework\AuthorizationInterface $authorization)
@@ -28,12 +31,7 @@ public function __construct(\Magento\Framework\AuthorizationInterface $authoriza
2831
}
2932

3033
/**
31-
* Validate logical condition for ui component
32-
* If validation passed block will be displayed
33-
*
34-
* @param array $arguments Attributes from element node.
35-
*
36-
* @return bool
34+
* @inheritdoc
3735
*/
3836
public function isVisible(array $arguments)
3937
{
@@ -45,6 +43,6 @@ public function isVisible(array $arguments)
4543
*/
4644
public function getName()
4745
{
48-
return 'acl';
46+
return self::NAME;
4947
}
5048
}

lib/internal/Magento/Framework/View/Layout/Condition/VisibilityConditionInterface.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@
88
/**
99
* Class VisibilityConditionInterface
1010
*
11-
* Introduces family of visibility conditions for layout elements at the backend.
11+
* Introduces family of visibility conditions for layout elements.
1212
* By using this interface a developer can specify dynamic rule for ui component visibility.
1313
*
1414
* Condition can be used by ui component declaration in layout
1515
*
16-
* <uiComponent name="form" visibilityCondition="ConditionFullClassPath" />
16+
* <uiComponent name="form">
17+
* <visibilityCondition name='can_show_awesome_element'>
18+
* <arguments>
19+
* <argument name="aclResource" xsi:type="string">Magento_Framework::awesome_page</argument>
20+
* <argument name="extraData" xsi:type="array"></argument>
21+
* <arguments>
22+
* </visibilityCondition>
23+
* </uiComponent>
1724
*
18-
* "visibilityCondition" just another optional attribute of ui component declaration
25+
* "visibilityCondition" just another optional child element of ui component declaration
1926
*/
2027
interface VisibilityConditionInterface
2128
{

lib/internal/Magento/Framework/View/Layout/ConfigCondition.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
use Magento\Framework\App\ScopeResolverInterface;
1212

1313
/**
14-
* Class ConfigCondition
14+
* Check that config flag is set to true,
1515
*/
1616
class ConfigCondition implements VisibilityConditionInterface
1717
{
18+
/**
19+
* Unique name.
20+
*/
21+
const NAME = 'ifconfig';
22+
1823
/**
1924
* @var ScopeConfigInterface
2025
*/
@@ -48,12 +53,7 @@ public function __construct(
4853
}
4954

5055
/**
51-
* Validate logical condition for ui component
52-
* If validation passed block will be displayed
53-
*
54-
* @param array $arguments Attributes from element node.
55-
*
56-
* @return bool
56+
* @inheritdoc
5757
*/
5858
public function isVisible(array $arguments)
5959
{
@@ -69,6 +69,6 @@ public function isVisible(array $arguments)
6969
*/
7070
public function getName()
7171
{
72-
return 'ifconfig';
72+
return self::NAME;
7373
}
7474
}

lib/internal/Magento/Framework/View/Layout/Reader/Visibility/Condition.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\View\Layout\Argument\Parser;
1111

1212
/**
13-
* Class Condition
13+
* Parse conditions from element.
1414
*/
1515
class Condition
1616
{
@@ -50,15 +50,6 @@ public function __construct(
5050
public function parseConditions(Element $element)
5151
{
5252
$visibilityConditions = [];
53-
/** @var $childElement Element */
54-
foreach ($element as $childElement) {
55-
if ($childElement->getName() === 'visibilityCondition') {
56-
$visibilityConditions[$childElement->getAttribute('name')] = [
57-
'name' => $childElement->getAttribute('className'),
58-
'arguments' => $this->evaluateArguments($childElement),
59-
];
60-
}
61-
}
6253
$configPath = (string)$element->getAttribute('ifconfig');
6354
if (!empty($configPath)) {
6455
$visibilityConditions['ifconfig'] = [
@@ -79,6 +70,16 @@ public function parseConditions(Element $element)
7970
];
8071
}
8172

73+
/** @var $childElement Element */
74+
foreach ($element as $childElement) {
75+
if ($childElement->getName() === 'visibilityCondition') {
76+
$visibilityConditions[$childElement->getAttribute('name')] = [
77+
'name' => $childElement->getAttribute('className'),
78+
'arguments' => $this->evaluateArguments($childElement),
79+
];
80+
}
81+
}
82+
8283
return $visibilityConditions;
8384
}
8485

@@ -110,14 +111,13 @@ private function evaluateArguments(Element $blockElement)
110111
}
111112

112113
/**
113-
* Get block arguments
114+
* @param Element $element
114115
*
115-
* @param Element $blockElement
116116
* @return array
117117
*/
118-
private function getArguments(Element $blockElement)
118+
private function getArguments(Element $element)
119119
{
120-
$arguments = $this->getElementsByType($blockElement, self::TYPE_ARGUMENTS);
120+
$arguments = $this->getElementsByType($element, self::TYPE_ARGUMENTS);
121121
// We have only one declaration of <arguments> node in block or its reference
122122
$argumentElement = reset($arguments);
123123
return $argumentElement ? $this->parseArguments($argumentElement) : [];

0 commit comments

Comments
 (0)