public function ItemList::filter in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php \Drupal\Core\TypedData\Plugin\DataType\ItemList::filter()
Filters the items in the list using a custom callback.
Parameters
callable $callback: The callback to use for filtering. Like with array_filter(), the callback is called for each item in the list. Only items for which the callback returns TRUE are preserved.
Return value
$this
Overrides ListInterface::filter
1 call to ItemList::filter()
- FieldItemList::filterEmptyItems in core/
lib/ Drupal/ Core/ Field/ FieldItemList.php - Filters out empty field items and re-numbers the item deltas.
File
- core/
lib/ Drupal/ Core/ TypedData/ Plugin/ DataType/ ItemList.php, line 270 - Contains \Drupal\Core\TypedData\Plugin\DataType\ItemList.
Class
- ItemList
- A generic list class.
Namespace
Drupal\Core\TypedData\Plugin\DataTypeCode
public function filter($callback) {
if (isset($this->list)) {
$removed = FALSE;
// Apply the filter, detecting if some items were actually removed.
$this->list = array_filter($this->list, function ($item) use ($callback, &$removed) {
if (call_user_func($callback, $item)) {
return TRUE;
}
else {
$removed = TRUE;
}
});
if ($removed) {
$this
->rekey();
}
}
return $this;
}