protected function SortableViewsStyleTrait::retrieveEligibleFieldsForWeight in Sortableviews 8
Returns list of eligible fields for storing weight.
Eligible fields can be either fields or Base Fields and must be of the integer type.
Return value
array An array whose keys and values are field machine names.
1 call to SortableViewsStyleTrait::retrieveEligibleFieldsForWeight()
File
- src/
SortableViewsStyleTrait.php, line 157
Class
- SortableViewsStyleTrait
- Provides sortable functionality for View styles.
Namespace
Drupal\sortableviewsCode
protected function retrieveEligibleFieldsForWeight() {
$field_options = [];
// Grab all entity fields.
$fields = $this->entityManager
->getStorage('field_storage_config')
->loadByProperties([
'entity_type' => $this->view
->getBaseEntityType()
->id(),
'type' => 'integer',
]);
foreach ($fields as $field) {
$field_options[$field
->getName()] = $field
->getName();
}
// Grab all entity base fields.
$base_fields = $this->entityFieldManager
->getBaseFieldDefinitions($this->view
->getBaseEntityType()
->id());
foreach ($base_fields as $base_field) {
if ($base_field
->getType() == 'integer') {
$field_options[$base_field
->getName()] = $base_field
->getName();
}
}
// From all picked fields, we remove those that are entity keys.
$keys = array_values($this->view
->getBaseEntityType()
->getKeys());
return array_diff($field_options, $keys);
}