Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AbstractComponent Class Reference
Inheritance diagram for AbstractComponent:
DataObject UiComponentInterface BlockInterface MassAction Action Bookmark Container Action Link DataSource DynamicRows ExportButton Filters AbstractFilter Form Collection AbstractElement AbstractDataType Field Fieldset HtmlContent Layout Tab Listing Columns Column MassAction Column Modal Paging Block

Public Member Functions

 __construct (ContextInterface $context, array $components=[], array $data=[])
 
 getContext ()
 
 getName ()
 
 prepare ()
 
 toHtml ()
 
 render ()
 
 addComponent ($name, UiComponentInterface $component)
 
 getComponent ($name)
 
 getChildComponents ()
 
 renderChildComponent ($name)
 
 getTemplate ()
 
 getConfiguration ()
 
 getJsConfig (UiComponentInterface $component)
 
 setData ($key, $value=null)
 
 getData ($key='', $index=null)
 
 prepareDataSource (array $dataSource)
 
 getDataSourceData ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from UiComponentInterface
 getComponentName ()
 

Protected Member Functions

 prepareChildComponent (UiComponentInterface $component)
 
 initObservers (array & $data=[])
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $context
 
 $components
 
 $componentData = []
 
 $dataSources = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Abstract class AbstractComponent

@api @SuppressWarnings(PHPMD.NumberOfChildren)

Since
100.0.2

Definition at line 24 of file AbstractComponent.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ContextInterface  $context,
array  $components = [],
array  $data = [] 
)

Constructor

Parameters
ContextInterface$context
UiComponentInterface[]$components
array$data

Definition at line 55 of file AbstractComponent.php.

59  {
60  $this->context = $context;
61  $this->components = $components;
62  $this->_data = array_replace_recursive($this->_data, $data);
63  $this->initObservers($this->_data);
64  }

Member Function Documentation

◆ addComponent()

addComponent (   $name,
UiComponentInterface  $component 
)

Add component

Parameters
string$name
UiComponentInterface$component
Returns
void

Implements UiComponentInterface.

Definition at line 170 of file AbstractComponent.php.

171  {
172  $this->components[$name] = $component;
173  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getChildComponents()

getChildComponents ( )

Get components

Returns
UiComponentInterface[]

Implements UiComponentInterface.

Definition at line 189 of file AbstractComponent.php.

◆ getComponent()

getComponent (   $name)
Parameters
string$name
Returns
UiComponentInterface

Implements UiComponentInterface.

Definition at line 179 of file AbstractComponent.php.

180  {
181  return isset($this->components[$name]) ? $this->components[$name] : null;
182  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getConfiguration()

getConfiguration ( )

Get component configuration

Returns
array

Implements UiComponentInterface.

Definition at line 224 of file AbstractComponent.php.

225  {
226  return (array)$this->getData('config');
227  }

◆ getContext()

getContext ( )

Get component context

Returns
ContextInterface

Implements UiComponentInterface.

Definition at line 71 of file AbstractComponent.php.

◆ getData()

getData (   $key = '',
  $index = null 
)

Component data getter

Parameters
string$key
string | int$index
Returns
mixed

Implements UiComponentInterface.

Definition at line 264 of file AbstractComponent.php.

265  {
266  return parent::getData($key, $index);
267  }
$index
Definition: list.phtml:44

◆ getDataSourceData()

getDataSourceData ( )

{Get Data Source data

Returns
array
}

Implements UiComponentInterface.

Definition at line 283 of file AbstractComponent.php.

284  {
285  return [];
286  }

◆ getJsConfig()

getJsConfig ( UiComponentInterface  $component)

Get configuration of related JavaScript Component (force extending the root component if component does not extend other component)

Parameters
UiComponentInterface$component
Returns
array

Definition at line 236 of file AbstractComponent.php.

237  {
238  $jsConfig = (array)$component->getData('js_config');
239  if (!isset($jsConfig['extends'])) {
240  $jsConfig['extends'] = $component->getContext()->getNamespace();
241  }
242  return $jsConfig;
243  }

◆ getName()

getName ( )

Get component name

Returns
string

Implements UiComponentInterface.

Definition at line 81 of file AbstractComponent.php.

82  {
83  return $this->getData('name');
84  }

◆ getTemplate()

getTemplate ( )

Get template

Returns
string

Implements UiComponentInterface.

Definition at line 214 of file AbstractComponent.php.

215  {
216  return $this->getData('template') . '.xhtml';
217  }

◆ initObservers()

initObservers ( array &  $data = [])
protected

Initiate observers

Parameters
array$data
Returns
void

Definition at line 294 of file AbstractComponent.php.

295  {
296  if (isset($data['observers']) && is_array($data['observers'])) {
297  foreach ($data['observers'] as $observerType => $observer) {
298  if (!is_object($observer)) {
299  $observer = $this;
300  }
301  if ($observer instanceof ObserverInterface) {
302  $this->getContext()->getProcessor()->attach($observerType, $observer);
303  }
304  unset($data['observers']);
305  }
306  }
307  }

◆ prepare()

prepare ( )

Prepare component configuration

Returns
void

Implements UiComponentInterface.

Definition at line 91 of file AbstractComponent.php.

92  {
93  $config = $this->getData('config');
94  if (isset($config['value']) && $config['value'] instanceof ValueSourceInterface) {
95  $config['value'] = $config['value']->getValue($this->getName());
96  }
97  $this->setData('config', (array)$config);
98 
99  $jsConfig = $this->getJsConfig($this);
100  if (isset($jsConfig['provider'])) {
101  unset($jsConfig['extends']);
102  $this->getContext()->addComponentDefinition($this->getName(), $jsConfig);
103  } else {
104  $this->getContext()->addComponentDefinition($this->getComponentName(), $jsConfig);
105  }
106 
107  if ($this->hasData('actions')) {
108  $this->getContext()->addActions($this->getData('actions'), $this);
109  }
110 
111  if ($this->hasData('html_blocks')) {
112  $this->getContext()->addHtmlBlocks($this->getData('html_blocks'), $this);
113  }
114 
115  if ($this->hasData('buttons')) {
116  $this->getContext()->addButtons($this->getData('buttons'), $this);
117  }
118  $this->context->getProcessor()->register($this);
119  $this->getContext()->getProcessor()->notify($this->getComponentName());
120  }
getJsConfig(UiComponentInterface $component)
$config
Definition: fraud_order.php:17

◆ prepareChildComponent()

prepareChildComponent ( UiComponentInterface  $component)
protected

Call prepare method in the component UI

Parameters
UiComponentInterface$component
Returns
$this
Since
100.1.0

Definition at line 129 of file AbstractComponent.php.

130  {
131  $childComponents = $component->getChildComponents();
132  if (!empty($childComponents)) {
133  foreach ($childComponents as $child) {
134  $this->prepareChildComponent($child);
135  }
136  }
137  $component->prepare();
138 
139  return $this;
140  }
prepareChildComponent(UiComponentInterface $component)

◆ prepareDataSource()

prepareDataSource ( array  $dataSource)

Prepare Data Source

Parameters
array$dataSource
Returns
array

Implements UiComponentInterface.

Definition at line 275 of file AbstractComponent.php.

276  {
277  return $dataSource;
278  }

◆ render()

render ( )

Render component

Returns
string

Implements UiComponentInterface.

Definition at line 157 of file AbstractComponent.php.

158  {
159  $result = $this->getContext()->getRenderEngine()->render($this, $this->getTemplate());
160  return $result;
161  }

◆ renderChildComponent()

renderChildComponent (   $name)

Render child component

Parameters
string$name
Returns
string

Implements UiComponentInterface.

Definition at line 200 of file AbstractComponent.php.

201  {
202  $result = null;
203  if (isset($this->components[$name])) {
204  $result = $this->components[$name]->render();
205  }
206  return $result;
207  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setData()

setData (   $key,
  $value = null 
)

Component data setter

Parameters
string | array$key
mixed$value
Returns
void

Implements UiComponentInterface.

Definition at line 252 of file AbstractComponent.php.

253  {
254  parent::setData($key, $value);
255  }
$value
Definition: gender.phtml:16

◆ toHtml()

toHtml ( )

Produce and return block's html output

Returns
string

Implements BlockInterface.

Definition at line 147 of file AbstractComponent.php.

148  {
149  $this->render();
150  }

Field Documentation

◆ $componentData

$componentData = []
protected

Definition at line 41 of file AbstractComponent.php.

◆ $components

$components
protected

Definition at line 36 of file AbstractComponent.php.

◆ $context

$context
protected

Definition at line 31 of file AbstractComponent.php.

◆ $dataSources

$dataSources = []
protected

Definition at line 46 of file AbstractComponent.php.


The documentation for this class was generated from the following file: