public function oneOfOptionsFromCallback(callable $valueLabelMapCallback, callable $labelFromValueLoader = null)
    {
        $valueLabelMapCallback = function (string $filter = null) use ($valueLabelMapCallback) {
            $options = [];

            foreach ($valueLabelMapCallback($filter) as $key => $value) {
                $options[] = $value instanceof IFieldOption ? $value : new FieldOption($key, $value);
            }

            return $options;
        };

        if ($labelFromValueLoader) {
            $labelFromValueLoader = function ($value) use ($labelFromValueLoader) {
                $option = $labelFromValueLoader($value);

                return $option ? new FieldOption($value, $option) : null;
            };
        }

        return $this->attr(FieldType::ATTR_OPTIONS, new CallbackFieldOptions($valueLabelMapCallback, $labelFromValueLoader));
    }
public function oneOfOptionsFromCallback(callable $valueLabelMapCallback, callable $labelFromValueLoader = null)
    {
        $valueLabelMapCallback = function (string $filter = null) use ($valueLabelMapCallback) {
            $options = [];

            foreach ($valueLabelMapCallback($filter) as $key => $value) {
                $options[] = $value instanceof IFieldOption ? $value : new FieldOption($key, $value);
            }

            return $options;
        };

        if ($labelFromValueLoader) {
            $labelFromValueLoader = function ($value) use ($labelFromValueLoader) {
                $option = $labelFromValueLoader($value);

                return $option ? new FieldOption($value, $option) : null;
            };
        }

        return $this->attr(FieldType::ATTR_OPTIONS, new CallbackFieldOptions($valueLabelMapCallback, $labelFromValueLoader));
    }
public function oneOfOptionsFromCallback ( callable $ valueLabelMapCallback , callable $ labelFromValueLoader = null ) { $ valueLabelMapCallback = function ( string $ filter = null ) use ( $ valueLabelMapCallback ) { $ options = [ ] ; foreach ( $ valueLabelMapCallback ( $ filter ) as $ key => $ value ) { $ options [ ] = $ value instanceof IFieldOption ? $ value : new FieldOption ( $ key , $ value ) ; } return $ options ; } ; if ( $ labelFromValueLoader ) { $ labelFromValueLoader = function ( $ value ) use ( $ labelFromValueLoader ) { $ option = $ labelFromValueLoader ( $ value ) ; return $ option ? new FieldOption ( $ value , $ option ) : null ; } ; } return $ this -> attr ( FieldType :: ATTR_OPTIONS , new CallbackFieldOptions ( $ valueLabelMapCallback , $ labelFromValueLoader ) ) ; }
Validates the input is one of the supplied values loaded from the supplied callback.
This is useful for loading options from a external data source.

Example:
<code>
->oneOfOptionsFromCallback(function (string $filter = null) {
return [
'value'         => 'Label',
'another-value' => 'Another Label',
];
});
</code>


@param callable      $valueLabelMapCallback
@param callable|null $labelFromValueLoader

@return static
Validates the input is one of the supplied values loaded from the supplied callback . This is useful for loading options from a external data source .