1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\ActivityBundle\Provider; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Util\ClassUtils; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\ActivityBundle\Manager\ActivityManager; |
8
|
|
|
use Oro\Bundle\UIBundle\Placeholder\PlaceholderProvider; |
9
|
|
|
use Oro\Bundle\UIBundle\Provider\WidgetProviderInterface; |
10
|
|
|
|
11
|
|
|
class ActivityActionWidgetProvider implements WidgetProviderInterface |
12
|
|
|
{ |
13
|
|
|
/** @var ActivityManager */ |
14
|
|
|
protected $activityManager; |
15
|
|
|
|
16
|
|
|
/** @var PlaceholderProvider */ |
17
|
|
|
protected $placeholderProvider; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param ActivityManager $activityManager |
21
|
|
|
* @param PlaceholderProvider $placeholderProvider |
22
|
|
|
*/ |
23
|
|
|
public function __construct( |
24
|
|
|
ActivityManager $activityManager, |
25
|
|
|
PlaceholderProvider $placeholderProvider |
26
|
|
|
) { |
27
|
|
|
$this->activityManager = $activityManager; |
28
|
|
|
$this->placeholderProvider = $placeholderProvider; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function supports($object) |
35
|
|
|
{ |
36
|
|
|
return $this->activityManager->hasActivityAssociations(ClassUtils::getClass($object)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function getWidgets($object) |
43
|
|
|
{ |
44
|
|
|
$result = []; |
45
|
|
|
|
46
|
|
|
$entityClass = ClassUtils::getClass($object); |
47
|
|
|
|
48
|
|
|
$items = $this->activityManager->getActivityActions($entityClass); |
49
|
|
|
foreach ($items as $item) { |
50
|
|
|
$buttonWidget = $this->placeholderProvider->getItem($item['button_widget'], ['entity' => $object]); |
51
|
|
|
if ($buttonWidget) { |
52
|
|
|
$widget = [ |
53
|
|
|
'name' => $item['button_widget'], |
54
|
|
|
'button' => $buttonWidget |
55
|
|
|
]; |
56
|
|
|
if (!empty($item['link_widget'])) { |
57
|
|
|
$linkWidget = $this->placeholderProvider->getItem($item['link_widget'], ['entity' => $object]); |
58
|
|
|
if ($linkWidget) { |
|
|
|
|
59
|
|
|
$widget['link'] = $linkWidget; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
if (isset($item['group'])) { |
63
|
|
|
$widget['group'] = $item['group']; |
64
|
|
|
} |
65
|
|
|
if (isset($item['priority'])) { |
66
|
|
|
$widget['priority'] = $item['priority']; |
67
|
|
|
} |
68
|
|
|
$result[] = $widget; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $result; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.