pages::extractValue($item, $field)

Makes sure to provide a valid value for each filter method no matter if an object or an array is given

  • $item (mixed)
  • $field (string)
  • return (mixed)

This documentation entry is inherited from the Collection class.

(For the Kirby CMS, this is an internal method, which is used by the collection filter methods. You can use it when defining your own collection filter methods.)

Example

Filter method:

// get all matching elements
collection::$filters['=='] = function($collection, $field, $value, $split = false) {

  foreach($collection->data as $key => $item) {

    if($split) {
      $values = str::split((string)collection::extractValue($item, $field), $split);
      if(!in_array($value, $values)) unset($collection->$key);
    } else if(collection::extractValue($item, $field) != $value) {
      unset($collection->$key);
    }

  }

  return $collection;

};

Is something missing or incorrect? Edit this page on Github…