Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
DataProvider Class Reference
Inheritance diagram for DataProvider:
ModifierPoolDataProvider AbstractDataProvider DataProviderInterface

Public Member Functions

 __construct ( $name, $primaryFieldName, $requestFieldName, EavValidationRules $eavValidationRules, CategoryCollectionFactory $categoryCollectionFactory, StoreManagerInterface $storeManager, \Magento\Framework\Registry $registry, Config $eavConfig, \Magento\Framework\App\RequestInterface $request, CategoryFactory $categoryFactory, array $meta=[], array $data=[], PoolInterface $pool=null)
 
 getMeta ()
 
 prepareMeta ($meta)
 
 getData ()
 
 getAttributesMeta (Type $entityType)
 
 getCurrentCategory ()
 
 getScopeLabel (EavAttribute $attribute)
 
 getDefaultMetaData ($result)
 
- Public Member Functions inherited from ModifierPoolDataProvider
 __construct ( $name, $primaryFieldName, $requestFieldName, array $meta=[], array $data=[], PoolInterface $pool=null)
 
 getData ()
 
- Public Member Functions inherited from AbstractDataProvider
 __construct ( $name, $primaryFieldName, $requestFieldName, array $meta=[], array $data=[])
 
 getCollection ()
 
 getName ()
 
 getPrimaryFieldName ()
 
 getRequestFieldName ()
 
 getMeta ()
 
 getFieldSetMetaInfo ($fieldSetName)
 
 getFieldsMetaInfo ($fieldSetName)
 
 getFieldMetaInfo ($fieldSetName, $fieldName)
 
 addFilter (\Magento\Framework\Api\Filter $filter)
 
 getSearchCriteria ()
 
 getSearchResult ()
 
 addField ($field, $alias=null)
 
 addOrder ($field, $direction)
 
 setLimit ($offset, $size)
 
 removeField ($field, $isAlias=false)
 
 removeAllFields ()
 
 getData ()
 
 count ()
 
 getConfigData ()
 
 setConfigData ($config)
 
 getAllIds ()
 
- Public Member Functions inherited from DataProviderInterface
 addFilter (\Magento\Framework\Api\Filter $filter)
 

Protected Member Functions

 addUseConfigSettings ($categoryData)
 
 addUseDefaultSettings ($category, $categoryData)
 
 filterFields ($categoryData)
 
 getFieldsMap ()
 

Protected Attributes

 $requestScopeFieldName = 'store'
 
 $loadedData
 
 $metaProperties
 
 $formElement
 
 $elementsWithUseConfigSetting
 
 $ignoreFields
 
 $eavValidationRules
 
 $registry
 
 $request
 
- Protected Attributes inherited from AbstractDataProvider
 $name
 
 $primaryFieldName
 
 $requestFieldName
 
 $meta = []
 
 $data = []
 
 $collection
 

Detailed Description

Class DataProvider

@api

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
101.0.0

Definition at line 37 of file DataProvider.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name,
  $primaryFieldName,
  $requestFieldName,
EavValidationRules  $eavValidationRules,
CategoryCollectionFactory  $categoryCollectionFactory,
StoreManagerInterface  $storeManager,
\Magento\Framework\Registry  $registry,
Config  $eavConfig,
\Magento\Framework\App\RequestInterface  $request,
CategoryFactory  $categoryFactory,
array  $meta = [],
array  $data = [],
PoolInterface  $pool = null 
)

DataProvider constructor

Parameters
string$name
string$primaryFieldName
string$requestFieldName
EavValidationRules$eavValidationRules
CategoryCollectionFactory$categoryCollectionFactory
StoreManagerInterface$storeManager
\Magento\Framework\Registry$registry
Config$eavConfig
\Magento\Framework\App\RequestInterface$request
CategoryFactory$categoryFactory
array$meta
array$data
PoolInterface | null$pool@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 167 of file DataProvider.php.

181  {
182  $this->eavValidationRules = $eavValidationRules;
183  $this->collection = $categoryCollectionFactory->create();
184  $this->collection->addAttributeToSelect('*');
185  $this->eavConfig = $eavConfig;
186  $this->registry = $registry;
187  $this->storeManager = $storeManager;
188  $this->request = $request;
189  $this->categoryFactory = $categoryFactory;
190 
191  parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
192  }

Member Function Documentation

◆ addUseConfigSettings()

addUseConfigSettings (   $categoryData)
protected

Add use config settings

Parameters
array$categoryData
Returns
array
Since
101.0.0

Definition at line 373 of file DataProvider.php.

374  {
375  foreach ($this->elementsWithUseConfigSetting as $elementsWithUseConfigSetting) {
376  if (!isset($categoryData['use_config'][$elementsWithUseConfigSetting])) {
377  if (!isset($categoryData[$elementsWithUseConfigSetting]) ||
378  ($categoryData[$elementsWithUseConfigSetting] == '')
379  ) {
380  $categoryData['use_config'][$elementsWithUseConfigSetting] = true;
381  } else {
382  $categoryData['use_config'][$elementsWithUseConfigSetting] = false;
383  }
384  }
385  }
386  return $categoryData;
387  }

◆ addUseDefaultSettings()

addUseDefaultSettings (   $category,
  $categoryData 
)
protected

Add use default settings

Parameters
\Magento\Catalog\Model\Category$category
array$categoryData
Returns
array
Deprecated:
102.0.0
Since
101.0.0

Definition at line 398 of file DataProvider.php.

399  {
400  if ($category->getExistsStoreValueFlag('url_key') ||
401  $category->getStoreId() === Store::DEFAULT_STORE_ID
402  ) {
403  $categoryData['use_default']['url_key'] = false;
404  } else {
405  $categoryData['use_default']['url_key'] = true;
406  }
407 
408  return $categoryData;
409  }

◆ filterFields()

filterFields (   $categoryData)
protected

Filter fields

Parameters
array$categoryData
Returns
array
Since
101.0.0

Definition at line 472 of file DataProvider.php.

473  {
474  return array_diff_key($categoryData, array_flip($this->ignoreFields));
475  }

◆ getAttributesMeta()

getAttributesMeta ( Type  $entityType)

Get attributes meta

Parameters
Type$entityType
Returns
array
Exceptions

Definition at line 325 of file DataProvider.php.

326  {
327  $meta = [];
328  $attributes = $entityType->getAttributeCollection();
329  /* @var EavAttribute $attribute */
330  foreach ($attributes as $attribute) {
331  $code = $attribute->getAttributeCode();
332  // use getDataUsingMethod, since some getters are defined and apply additional processing of returning value
333  foreach ($this->metaProperties as $metaName => $origName) {
334  $value = $attribute->getDataUsingMethod($origName);
335  $meta[$code][$metaName] = $value;
336  if ('frontend_input' === $origName) {
337  $meta[$code]['formElement'] = isset($this->formElement[$value])
338  ? $this->formElement[$value]
339  : $value;
340  }
341  if ($attribute->usesSource()) {
342  $meta[$code]['options'] = $attribute->getSource()->getAllOptions();
343  }
344  }
345 
346  $rules = $this->eavValidationRules->build($attribute, $meta[$code]);
347  if (!empty($rules)) {
348  $meta[$code]['validation'] = $rules;
349  }
350 
351  $meta[$code]['scopeLabel'] = $this->getScopeLabel($attribute);
352  $meta[$code]['componentType'] = Field::NAME;
353  }
354 
355  $result = [];
356  foreach ($meta as $key => $item) {
357  $result[$key] = $item;
358  $result[$key]['sortOrder'] = 0;
359  }
360 
362 
363  return $result;
364  }
$value
Definition: gender.phtml:16
$attributes
Definition: matrix.phtml:13
$code
Definition: info.phtml:12

◆ getCurrentCategory()

getCurrentCategory ( )

Get current category

Returns
Category
Exceptions
NoSuchEntityException
Since
101.0.0

Definition at line 418 of file DataProvider.php.

419  {
420  $category = $this->registry->registry('category');
421  if ($category) {
422  return $category;
423  }
424  $requestId = $this->request->getParam($this->requestFieldName);
425  $requestScope = $this->request->getParam($this->requestScopeFieldName, Store::DEFAULT_STORE_ID);
426  if ($requestId) {
427  $category = $this->categoryFactory->create();
428  $category->setStoreId($requestScope);
429  $category->load($requestId);
430  if (!$category->getId()) {
431  throw NoSuchEntityException::singleField('id', $requestId);
432  }
433  }
434  return $category;
435  }

◆ getData()

getData ( )

Get data

Returns
array
Since
101.0.0

Implements DataProviderInterface.

Definition at line 297 of file DataProvider.php.

298  {
299  if (isset($this->loadedData)) {
300  return $this->loadedData;
301  }
302  $category = $this->getCurrentCategory();
303  if ($category) {
304  $categoryData = $category->getData();
305  $categoryData = $this->addUseConfigSettings($categoryData);
306  $categoryData = $this->filterFields($categoryData);
307  $categoryData = $this->convertValues($category, $categoryData);
308 
309  $this->loadedData[$category->getId()] = $categoryData;
310  }
311 
312  return $this->loadedData;
313  }

◆ getDefaultMetaData()

getDefaultMetaData (   $result)

Category's fields default values

Parameters
array$result
Returns
array
Since
101.0.0

Definition at line 525 of file DataProvider.php.

526  {
527  $result['parent']['default'] = (int)$this->request->getParam('parent');
528  $result['use_config.available_sort_by']['default'] = true;
529  $result['use_config.default_sort_by']['default'] = true;
530  $result['use_config.filter_price_range']['default'] = true;
531 
532  return $result;
533  }

◆ getFieldsMap()

getFieldsMap ( )
protected
Returns
array
Since
101.0.0

Definition at line 539 of file DataProvider.php.

540  {
541  return [
542  'general' => [
543  'parent',
544  'path',
545  'is_active',
546  'include_in_menu',
547  'name',
548  ],
549  'content' => [
550  'image',
551  'description',
552  'landing_page',
553  ],
554  'display_settings' => [
555  'display_mode',
556  'is_anchor',
557  'available_sort_by',
558  'use_config.available_sort_by',
559  'default_sort_by',
560  'use_config.default_sort_by',
561  'filter_price_range',
562  'use_config.filter_price_range',
563  ],
564  'search_engine_optimization' => [
565  'url_key',
566  'url_key_create_redirect',
567  'url_key_group',
568  'meta_title',
569  'meta_keywords',
570  'meta_description',
571  ],
572  'assign_products' => [
573  ],
574  'design' => [
575  'custom_use_parent_settings',
576  'custom_apply_to_products',
577  'custom_design',
578  'page_layout',
579  'custom_layout_update',
580  ],
581  'schedule_design_update' => [
582  'custom_design_from',
583  'custom_design_to',
584  ],
585  'category_view_optimization' => [
586  ],
587  'category_permissions' => [
588  ],
589  ];
590  }

◆ getMeta()

getMeta ( )

Returns
array

Since
102.0.0

Implements DataProviderInterface.

Definition at line 198 of file DataProvider.php.

199  {
200  $meta = parent::getMeta();
201  $meta = $this->prepareMeta($meta);
202 
203  $category = $this->getCurrentCategory();
204 
205  if ($category) {
206  $meta = $this->addUseDefaultValueCheckbox($category, $meta);
207  }
208  // Default and custom settings
209  return $meta;
210  }

◆ getScopeLabel()

getScopeLabel ( EavAttribute  $attribute)

Retrieve label of attribute scope

GLOBAL | WEBSITE | STORE

Parameters
EavAttribute$attribute
Returns
string
Since
101.0.0

Definition at line 446 of file DataProvider.php.

447  {
448  $html = '';
449  if (!$attribute || $this->storeManager->isSingleStoreMode()
450  || $attribute->getFrontendInput() === AttributeInterface::FRONTEND_INPUT
451  ) {
452  return $html;
453  }
454  if ($attribute->isScopeGlobal()) {
455  $html .= __('[GLOBAL]');
456  } elseif ($attribute->isScopeWebsite()) {
457  $html .= __('[WEBSITE]');
458  } elseif ($attribute->isScopeStore()) {
459  $html .= __('[STORE VIEW]');
460  }
461 
462  return $html;
463  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ prepareMeta()

prepareMeta (   $meta)

Prepare meta data

Parameters
array$meta
Returns
array
Since
101.0.0

Definition at line 261 of file DataProvider.php.

262  {
263  $meta = array_replace_recursive($meta, $this->prepareFieldsMeta(
264  $this->getFieldsMap(),
265  $this->getAttributesMeta($this->eavConfig->getEntityType('catalog_category'))
266  ));
267 
268  return $meta;
269  }

Field Documentation

◆ $eavValidationRules

$eavValidationRules
protected

Definition at line 105 of file DataProvider.php.

◆ $elementsWithUseConfigSetting

$elementsWithUseConfigSetting
protected
Initial value:
= [
'available_sort_by',
'default_sort_by',
'filter_price_range',
]

Definition at line 84 of file DataProvider.php.

◆ $formElement

$formElement
protected
Initial value:
= [
'text' => 'input',
'boolean' => 'checkbox',
]

Definition at line 73 of file DataProvider.php.

◆ $ignoreFields

$ignoreFields
protected
Initial value:
= [
'products_position',
'position'
]

Definition at line 96 of file DataProvider.php.

◆ $loadedData

$loadedData
protected

Definition at line 49 of file DataProvider.php.

◆ $metaProperties

$metaProperties
protected
Initial value:
= [
'dataType' => 'frontend_input',
'visible' => 'is_visible',
'required' => 'is_required',
'label' => 'frontend_label',
'sortOrder' => 'sort_order',
'notice' => 'note',
'default' => 'default_value',
'size' => 'multiline_count',
]

Definition at line 56 of file DataProvider.php.

◆ $registry

$registry
protected

Definition at line 111 of file DataProvider.php.

◆ $request

$request
protected

Definition at line 117 of file DataProvider.php.

◆ $requestScopeFieldName

$requestScopeFieldName = 'store'
protected

Definition at line 43 of file DataProvider.php.


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