sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function render(Model $model, $source) { $attachment = $this->resolveModelSource($model, $source); if ( ! ($attachment instanceof AttachmentInterface)) { return null; } return $attachment->url(); }
Renders a display value to print to the export. @param Model $model @param mixed $source source column, method name or value @return string
entailment
public function addToNavigation($badge = null) { $nav = $this->getNavigation(); if ($this->hasParentPageId()) { $nav = $nav->getPages()->findById($this->getParentPageId()); if (is_null($nav)) { throw new InvalidArgumentException( sprintf( ...
{@inheritdoc}
entailment
protected function makePage($badge = null) { $page = new Page($this); $page->setPriority($this->getPriority()) ->setIcon($this->getIcon()) ->setId($this->getPageId()) ->setAccessLogic(function () { return $this->isDisplay(); }); ...
Make page @param string|Closure|null $badge @return \Sco\Admin\Navigation\Page
entailment
protected function performInit() { $this->prepareTargetRoute() ->prepareParentParameter() ->checkForMorphToRelation(); // Check permissions $permissions = $this->actionData->permissions(); if (empty($permissions)) { $this->isPermitted = true; ...
Performs initialization. Override this to customize strategy implementations.
entailment
public function link(Model $model) { if ( ! $this->routePrefix || ! $this->isPermitted) { return false; } // If the relation is morphTo, the key needs to be prepared with type:key identicator if ($this->isMorphTo) { // todo: this needs to be fixed ...
Returns the action link for a given model instance. @param Model $model @return string|false
entailment
protected function getOtherModelClass() { $this->otherModelClass = array_get($this->actionData->options(), 'model'); if ( ! $this->otherModelClass) { throw new UnexpectedValueException("No target model class set in options"); } if ( ! is_a($this->otherModelClass, Model:...
Returns the model FQN for the target model for the link. If the relationship is MorphTo, we cannot know the model class in every case. @return string
entailment
protected function getRelationName() { $relation = array_get($this->actionData->options(), 'relation'); if ($relation) { return $relation; } /** @var ModelInformationRepositoryInterface $infoRepository */ $infoRepository = app(ModelInformationRepositoryInterface...
Returns configured relation name for children link. Falls back to list.parents relation name if exactly one given. @return string|false
entailment
public function index() { if ($this->luceneIndex->count() !== 0) { $this->luceneIndex = Lucene::create($this->indexDirectory); } /** @var \yii\db\ActiveRecord $modelName */ foreach ($this->models as $modelName) { /** @var behaviors\SearchBehavior $model */ ...
Indexing the contents of the specified models. @throws InvalidConfigException
entailment
public function find($term, $fields = []) { Wildcard::setMinPrefixLength($this->minPrefixLength); Lucene::setResultSetLimit($this->resultsLimit); if (empty($fields)) { return [ 'results' => $this->luceneIndex->find($term), 'query' => $term ...
Search page for the term in the index. @param string $term @param array $fields (string => string) @return array ('results' => \ZendSearch\Lucene\Search\QueryHit[], 'query' => string)
entailment
public function delete($text, $field = null) { $query = new Term(new IndexTerm($text, $field)); $hits = $this->luceneIndex->find($query); foreach ($hits as $hit) { $this->luceneIndex->delete($hit); } }
Delete document from the index. @param string $text @param string|null $field
entailment
protected function checkListParents($update = true) { if (empty($this->getModelInformation()->list->parents)) { return $this; } $this->retrieveActiveParentFromSession(); $this->collectListParentHierarchy(); if ($update) { $this->updateActiveParent();...
Checks and loads list parent from the session. @param bool $update whether to check for updates through the 'parent' request param @return $this
entailment
protected function showsTopParentsOnly() { $relation = $this->getModelInformation()->list->default_top_relation; // If the default is to restrict to top-level only, // or the reverse with a user-initiated reversal (relation = false): // Restrict the query to top level. retu...
Returns whether the index will only show the top level parents. @return bool
entailment
protected function applyListParentContext() { $parents = $this->getModelInformation()->list->parents; if (empty($parents)) { return $this; } if ($this->listParentRelation) { $contextKey = $this->listParentRelation . $this->getListParentSeparator() . $this->l...
Applies the context for the current list parent scope. Must be called before other list memory is accessed, since it affects the sub-context of the memory. @return $this
entailment
protected function applyListParentToQuery($query) { if ( ! $this->listParentRelation) { if ($this->showsTopParentsOnly()) { $query->has($this->getModelInformation()->list->default_top_relation, '<', 1); } return $this; } // Use list pare...
Applies the active list parent as a filter on a query builder. @param Builder $query @return $this
entailment
protected function collectListParentHierarchy($relation = null, $key = null) { $this->listParents = []; if (null === $relation) { $relation = $this->listParentRelation; $key = $this->listParentRecordKey; } if ( ! $relation || null === $key) { ...
Looks up the current full list parent hierarchy chain to the top level. @param string|null $relation if not set, uses currently stored values @param mixed|null $key
entailment
protected function updateActiveParent() { // If no update is required, return immediately if ( ! request()->has('parents') && ! request()->filled('home') && ! request()->has('parent')) { return $this; } $separator = $this->getListParentSeparator(); // Check for ...
Updates the active list parent if the request parameter is set. @return $this
entailment
protected function normalizeListParentParameter($parent) { $separator = $this->getListParentSeparator(); if (is_integer($parent) && $parent < 0 || is_string($parent) && preg_match('#-\d+#', $parent)) { $parent = (int) $parent; if ($parent < 0) { // The the p...
Normalizes 'parent' query parameter for list parent update. @param mixed $parent @return int|null
entailment
protected function updateActiveParents(array $parents) { $modelInfo = $this->getModelInformation(); $modelClass = $modelInfo->modelClass(); $model = new $modelClass; $previousContext = null; $previousParent = array_shift($parents); $separator ...
Update a full list parent chain. @param array $parents should be last-first ordered, strings with :-separated relaton:key
entailment
protected function enrichListParents() { if (empty($this->listParents)) { return; } // Mark for each list parents entry how the query params should be set up $queries = []; $previousModel = $this->getModelInformation()->modelClass(); /** @var Lis...
Enriches list parent data for view.
entailment
protected function clearEntireListParentHierarchy() { $separator = $this->getListParentSeparator(); foreach ($this->listParents as $parent) { if ( ! $parent || is_string($parent) && false === strpos($parent, $separator)) { break; } // Unset pare...
Clears list parent chain as currently memorized.
entailment
protected function retrieveActiveParentFromSession() { $parent = $this->getListParentDataFromMemory($this->globalSubContext()); if (false === $parent || null === $parent) { $this->listParentRelation = $parent; $this->listParentRecordKey = null; return; }...
Retrieves the currently set 'global' list parent from the session and stores it locally.
entailment
protected function getListParentInformation( Model $model, $relation, $key, ModelInformationInterface $info, $recurse = false ) { // Don't attempt to load relation methods if the parent relation is not configured if ( empty($info->list->parents) ...
Returns information about a list parent, or all list parents in the chain. Exceptions will be thrown if there are logical problems with the chain. @param Model $model @param string $relation @param mixed $key...
entailment
protected function getModelByKey(Model $model, $key) { return $model::withoutGlobalScopes() ->where($model->getKeyName(), $key) ->first(); }
Returns model instance by key. @param Model $model @param mixed $key @return Model|null
entailment
protected function getModuleByModel(Model $model) { /** @var ModuleManagerInterface $modules */ $modules = app(ModuleManagerInterface::class); return $modules->getByAssociatedClass(get_class($model)); }
Returns the module for a given model. @param Model $model @return ModuleInterface|false
entailment
protected function isFieldValueBeDerivableFromListParent($field) { if ( ! $this->hasActiveListParent()) { return false; } $listParentData = $this->getListParentDataForRelation($this->listParentRelation); if ( ! $listParentData) { return false; } ...
Returns whether the set list parent corresponds to a given field key. @param string $field @return bool
entailment
protected function getListParentDataFromMemory($subContext, $context = null) { $memory = $this->getListMemory(); $oldContext = $memory->getContext(); $oldSubContext = $memory->getSubContext(); if (null !== $context) { $memory->setContext($context); } ...
Retrieves list parent data from memory and resets memory context. @param string|null $subContext @param string|null $context @return array|false|null
entailment
protected function setListParentDataInMemory($relation, $key, $subContext, $context = null) { $memory = $this->getListMemory(); $oldContext = $memory->getContext(); $oldSubContext = $memory->getSubContext(); if (null !== $context) { $memory->setContext($context); ...
Stores list parent data in memory and resets memory context. @param string|null|false $relation @param mixed|null $key @param string|null $subContext @param string|null $context
entailment
protected function getRelationMappedMorphType($class) { $map = Relation::morphMap(); if (empty($map)) { return ltrim($class, '\\'); } if ( false !== ($type = array_search($class, $map)) || false !== ($type = array_search(ltrim($class, '\\'), $map)) ...
Returns morph relation type string for a model class, or returns class if not mapped. @param string $class @return string
entailment
protected function getRelationMappedMorphClass($type) { $map = Relation::morphMap(); if (empty($map)) { return $type; } return array_get($map, $type, ltrim($type, '\\')); }
Returns morph relation class string for a morph relation type, or type if already a class. @param string $type @return string
entailment
public function interpret($information) { $this->raw = $information; $this->interpretReferenceData() ->interpretListData() ->interpretFormData() ->interpretShowData() ->interpretExportData(); return $this->createInformationInstance(); ...
Interprets raw CMS model information as a model information object. @param array $information @return ModelInformationInterface|ModelInformation
entailment
protected function normalizeScopeArray(array $scopes, $parentKey = 'list.scopes') { $scopes = $this->normalizeStandardArrayProperty( $scopes, 'strategy', ModelScopeData::class, $parentKey ); // Make sure that each scope entry has at least a me...
Normalizes an array with scope data. @param array $scopes @param string $parentKey @return array
entailment
protected function normalizeStandardArrayProperty( array $source, $standardProperty, $objectClass = null, $parentKey = null ) { $normalized = []; foreach ($source as $key => $value) { // key may be present as values, when it is included just for order or...
Normalizes a standard array property. This assumes sections such as list.columns, where keys are required designators. @param array $source @param string $standardProperty property to set for string values in normalized array @param null|string $objectClass dataobject FQN to interpret as @param null|s...
entailment
protected function normalizeKeyLessArrayProperty( array $source, $standardProperty, $objectClass = null, $parentKey = null ) { $normalized = []; foreach ($source as $index => $value) { // if value is just a string, it is the standard property ...
Normalizes a standard array property for inassociative data. This assumes sections such as list.columns, where values should appear without keys. @param array $source @param string $standardProperty property to set for string values in normalized array @param null|string $objectClass dataobject FQN to...
entailment
protected function makeClearedDataObject($objectClass, array $data, $parentKey = null) { /** @var AbstractDataObject $object */ $object = new $objectClass(); $object->clear(); try { $object->setAttributes($data); } catch (ModelConfigurationDataException $e) { ...
Makes a fresh dataobject with its defaults cleared before filling it with data. @param string $objectClass @param array $data @param null|string $parentKey @return AbstractDataObject @throws ModelConfigurationDataException
entailment
protected function performEnrichment() { $strategies = $this->info->export->strategies; foreach ($strategies as $key => $strategyData) { if (empty($strategyData['strategy'])) { $strategies[ $key ]['strategy'] = $key; } } $this->info->export-...
Performs enrichment.
entailment
protected function getReference(Model $model) { $reference = $this->getReferenceValue($model); return $this->wrapWithLink($reference, $this->getLinkForReferenceModel($model)); }
Returns a reference representation for a single model. @param Model $model @return string
entailment
protected function getLinkForReferenceModel(Model $model) { $routeName = $this->getRouteHelper()->getRouteNameForModelClass(get_class($model), true); $action = $this->determineRouteAction($model); return route($routeName . '.' . $action, $model->getKey()); }
Returns action link for given model. @param Model $model @return string
entailment
protected function determineRouteAction(Model $model) { $routeHelper = $this->getRouteHelper(); $permissionPrefix = $routeHelper->getPermissionPrefixForModelSlug( $routeHelper->getRouteSlugForModelClass(get_class($model)) ); // Change the action to show if we don't have...
Returns route action for given model. The edit action is default, with a fallback to show if no permission is granted. @param Model $model @return string
entailment
public function handle() { $this->line(''); $this->line('************************'); $this->line(' Welcome to Sco-Admin '); $this->line('************************'); $this->publish(); $this->routes(); $this->info('Successfully Installed Sco-Admin!'); }
Execute the console command. @return mixed
entailment
protected function castValueAsJson($value) { $value = $this->asJson($value); if ($value === false) { throw new \RuntimeException( sprintf( "Unable to encode value [%s] for element [%s] to JSON: %s.", $this->getName(), ...
Cast the given value to JSON. @param mixed $value @return string
entailment
protected function castValue($value) { if (is_null($value)) { return $value; } if ($this->isElementOfDate() && $this->isDateCastable()) { return $this->fromDateTime($value); } switch ($this->getCast()) { case 'int': case 'inte...
Cast a value to a native PHP type. @param $value @return array
entailment
protected function getModelClassFromValue($value) { if (empty($value)) return null; $parts = explode(static::CLASS_AND_KEY_SEPARATOR, $value, 2); return $parts[0]; }
Returns the model class part of a morph model/key combination value. @param string $value @return string|null
entailment
protected function getModelKeyFromValue($value) { if (empty($value)) return null; $parts = explode(static::CLASS_AND_KEY_SEPARATOR, $value, 2); if (count($parts) < 2) { throw new UnexpectedValueException("Morph model value is not formatted as 'class:key'."); } ...
Returns the model key part of a morph model/key combination value. @param string $value @return mixed|null
entailment
protected function getValueFromRelationQuery($query) { // Prevent looking up connected model when foreign keys are NULL to prevent query errors. /** @var MorphTo $query */ $typeName = $query->getMorphType(); $keyName = $query->getForeignKey(); if ( ! $this->model->{$typeNa...
Returns the value per relation for a given relation query builder. @param Builder|Relation $query @return mixed|null
entailment
protected function getValueFromModel($model) { if ( ! ($model instanceof Model)) { return null; } return get_class($model) . static::CLASS_AND_KEY_SEPARATOR . $model->getKey(); }
Returns the value for a single related model. @param Model|null $model @return mixed|null
entailment
protected function getModelByKey($model, $key) { if (is_string($model)) { $model = new $model; } /** @var Model $model */ return $model->withoutGlobalScopes()->find($key); }
Finds a (to be related) model by its key. @param string|Model $model @param string $key @return Model|null
entailment
protected function storeActiveTranslationLocale($request) { $locale = $request->input(DefaultModelController::ACTIVE_TRANSLATION_LOCALE_KEY); if ( ! $locale) return; /** @var TranslationLocaleHelperInterface $helper */ $helper = app(TranslationLocaleHelperInterface::class); ...
Stores active translation locale in session. @param \Illuminate\Http\Request $request
entailment
protected function decorateFieldData(array $data) { // Get the key-reference pairs required to fill the drop-down and group them by the model class. // Also get displayable labels for each model class. $modelClasses = $this->getMorphableModels(); $modelLabels = []; $referen...
Enriches field data before passing it on to the view. @param array $data @return array
entailment
protected function buildClass($name) { $replace = array_merge( ['DummyDisplayType' => $this->getDisplayType()], $this->buildObserverReplacements(), $this->buildModelReplacements() ); return str_replace( array_keys($replace), array_...
Build the class with the given name. @param string $name @return string
entailment
protected function parseObserver($observer) { if (preg_match('([^A-Za-z0-9_/\\\\])', $observer)) { throw new InvalidArgumentException('Observer name contains invalid characters.'); } $observer = str_replace('/', '\\', $observer); if (! Str::startsWith($observer, [ ...
Get the fully-qualified observer class name. @param string $observer @return string
entailment
public function render(Model $model, $source) { $source = $this->resolveModelSource($model, $source); $date = $this->interpretAsDate($source); if ( ! $date) { return ''; } return e($date->format($this->getFormat())); }
Renders a display value to print to the list view. @param Model $model @param mixed $source source column, method name or value @return string
entailment
protected function interpretAsDate($value) { if (null === $value || 0 === $value || '' === $value) { return null; } if ($value instanceof DateTime) { return $value; } if (is_string($value)) { return new Carbon($value); } ...
Parses a source value as a boolean value. @param mixed $value @return DateTime|null
entailment
protected function setCurrentModelClass() { if ( ! $this->router->isModelRoute()) { $this->currentModelClass = null; return $this; } $info = $this->repository->getByKey( $this->router->getModuleKeyForCurrentRoute() ); if ($info) { ...
Sets the active and current model class based on the current request.
entailment
public function info() { if (empty($this->activeModelClass)) { $info = false; } else { $info = $this->repository->getByModelClass($this->activeModelClass); } // Reset the active model class for future calls $this->activeModelClass = $this->currentMode...
Returns model information data object for active model. @return ModelInformation|false
entailment
protected function performEnrichment() { if ( ! count($this->info->list->columns)) { $this->fillDataForEmpty(); } else { $this->enrichCustomData(); } }
Performs enrichment.
entailment
protected function fillDataForEmpty() { // Fill list references if they are empty $columns = []; // Add columns for attributes foreach ($this->info->attributes as $attribute) { if ($attribute->hidden || ! $this->shouldAttributeBeDisplayedByDefault($attribute, $this->inf...
Fills column data if no custom data is set.
entailment
protected function enrichCustomData() { // Check filled columns and enrich them as required // Note that these can be either attributes or relations $columns = []; foreach ($this->info->list->columns as $key => $column) { try { $this->enrichColumn($key,...
Enriches existing user configured data.
entailment
protected function enrichColumn($key, ModelListColumnDataInterface $column, array &$columns) { $normalizedRelationName = $this->normalizeRelationName($key); // Check if we can enrich, if we must. if ( ! isset($this->info->attributes[ $key ]) && ! isset($this->info->relations...
Enriches a single list column and saves the data. @param ModelListColumnDataInterface $column @param string $key @param array $columns by reference, data array to build, updated with enriched data
entailment
protected function makeModelListColumnDataForAttributeData(ModelAttributeData $attribute, ModelInformationInterface $info) { $primaryIncrementing = $attribute->name === $this->model->getKeyName() && $info->incrementing; $sortable = ( $attribute->isNumeric() || in_array($att...
Makes data set for list column given attribute data. @param ModelAttributeData $attribute @param ModelInformationInterface|ModelInformation $info @return ModelListColumnData
entailment
protected function makeModelListColumnDataForRelationData(ModelRelationData $relation) { return new ModelListColumnData([ 'source' => $relation->method, 'strategy' => $this->determineListDisplayStrategyForRelation($relation), 'label' => ucfirst(str_...
Makes data set for list column given relation data. @param ModelRelationData $relation @return ModelListColumnData
entailment
protected function initializeForModelRoute() { $this->moduleKey = $this->routeHelper->getModuleKeyForCurrentRoute(); $this->modelSlug = $this->routeHelper->getModelSlugForCurrentRoute(); $this->permissionPrefix = $this->routeHelper->getPermissionPrefixForModelSlug($this->modelS...
Initializes controller and checks context expecting a model route. @return $this
entailment
protected function initializeModelRepository() { /** @var ModelRepositoryFactoryInterface $factory */ $factory = app(ModelRepositoryFactoryInterface::class); $this->modelRepository = $factory->make($this->modelInformation->modelClass()); $this->applyRepositoryContext(); re...
Sets up the model repository for the relevant model. @return $this
entailment
protected function getFormFieldStoreStrategyParametersForField(ModelFormFieldDataInterface $field) { $strategy = $field->store_strategy ?: ''; $pos = strpos($strategy, ':'); if (false === $pos) { return []; } return array_map('trim', explode(',', substr($strate...
Returns parameters that should be passed into the store strategy instance. @param ModelFormFieldDataInterface|ModelFormFieldData $field @return array
entailment
public function render($key, $value) { if ('' === $value) { $value = null; } if (null !== $value) { $value = $value ? '1' : '0'; } return view( 'cms-models::model.partials.filters.dropdown-boolean', [ 'label' ...
Applies a strategy to render a filter field. @param string $key @param mixed $value @return string|View
entailment
public function render(Model $model, $source) { $value = $this->resolveModelSource($model, $source); if (null === $value) { return null; } if ($value) { return cms_trans('common.boolean.true'); } return cms_trans('common.boolean.false'); ...
Renders a display value to print to the export. @param Model $model @param mixed $source source column, method name or value @return string
entailment
protected function performEnrichment() { if ( ! count($this->info->form->fields)) { return; } $this->layoutFields = $this->info->form->getLayoutFormFieldKeys(); $this ->enrichCreateRules() ->enrichUpdateRules(); }
Performs enrichment of validation rules based on form field strategies. @throws ModelInformationEnrichmentException
entailment
protected function getCustomizedRuleKeysToExclude(array $customRules) { $keys = []; foreach ($customRules as $key => $ruleParts) { // If the set value for this key is false/null, the rule must be ignored entirely. // This will disable enrichment using form field rules. ...
Returns keys for rules that should not be included by custom configuration. @param array $customRules @return string[]
entailment
protected function getCustomizedRuleKeysToKeepDefault(array $customRules) { $keys = []; foreach ($customRules as $key => $ruleParts) { // If the configured value is the name of a key (and so it is a non-associative // part of the rules), it indicates that the default should...
Returns keys for rules that should be kept from the default generated rules, even when in replace mode. @param array $customRules @return string[]
entailment
protected function enrichRulesNew( array $customRules, array $generatedRules, $replace, array $excludeKeys, array $keepDefaultKeys, array $generatedRulesMap ) { // so use them as a starting point. // If custom rules are configured, they should not over...
Enriches rules and returns the enriched rules array. @param array $customRules rules custom-defined in the configuration, normalized @param array $generatedRules rules generated by the CMS, normalized @param bool $replace whether to replace rules entirely (and not enricht non-present...
entailment
protected function getFormFieldGeneratedRules($forCreate = true) { $this->generatedRulesMap = []; $rules = []; foreach ($this->info->form->fields as $field) { try { $this->getFormFieldGeneratedRule($field, $forCreate, $rules); } ca...
Returns rules determined by form field strategies. @param bool $forCreate @return array @throws ModelInformationEnrichmentException
entailment
protected function getFormFieldGeneratedRule(ModelFormFieldDataInterface $field, $forCreate, array &$rules) { $this->generatedRulesMap[ $field->key() ] = []; if ( ! $this->isFormFieldRelevant($field, $forCreate)) { return; } // The rules returned by a strategy (specific...
Updates collected rules array with rules based on form field data. @param ModelFormFieldDataInterface|ModelFormFieldData $field @param bool $forCreate @param array $rules by reference
entailment
protected function normalizeValidationRuleSourceDataFromConfig(array $rules) { // Remove entries to be ignored and excluded $filteredRules = array_filter($rules, function ($rule, $key) { return false !== $rule && ! empty($rule) && ! (is_string($rule) &...
Normalizes custom configured rules data to include only specified rules. This leaves out rules nullified to exclude them, as well as rules marked to be included/kept as generated by default. @param array $rules @return ValidationRuleDataInterface[]
entailment
protected function normalizeValidationRuleSourceData($rules) { if (false === $rules || empty($rules)) { return []; } if (is_string($rules)) { $rules = (array) $rules; } if ( ! is_array($rules)) { throw new UnexpectedValueException("Form f...
Normalizes generated validation rule data to an array of data object instances. The entries will be collapsed to one per key, and the array will be keyed by the key. @param mixed $rules @return ValidationRuleDataInterface[]
entailment
protected function normalizeRulesProperty($rules, $key) { if ($rules instanceof ValidationRuleDataInterface) { return $rules; } if (is_string($rules)) { // Convert Laravel's pipe-syntax to array $rules = explode('|', $rules); } if ( ! is_...
Normalizes rules data for a single validation rule key. @param mixed $rules @param int|string $key The source array key @return ValidationRuleDataInterface
entailment
protected function makeValidationRuleDataFromSpecialArraySyntax(array $rules, $key) { $data = new ValidationRuleData( array_get($rules, 'rules', []), array_get($rules, 'key', is_numeric($key) ? null : $key) ); if (array_has($rules, 'translated')) { $data-...
Makes a validation rule data object from a special configuration array. @param array $rules @param null|string $key @return ValidationRuleData
entailment
protected function getFormFieldModelInformationBasedRules(ModelFormFieldDataInterface $field) { $key = $field->key(); $modelInformation = $this->getModelInformation(); if (array_key_exists($key, $modelInformation->attributes)) { return $this->getAttributeValidatio...
Returns validation rules based on model information for a given form field. @param ModelFormFieldDataInterface|ModelFormFieldData|null $field @return array|false
entailment
protected function replaceFieldKeyPlaceholderInValidationRules(ModelFormFieldDataInterface $field, array $rules) { foreach ($rules as $rule) { // Prepare field prefix with locale placeholder if relevant $fieldPrefix = $field->key(); if ($rule->isTranslated() && $rule->l...
Replaces placeholders for the field key (as prefix). @param ModelFormFieldDataInterface $field @param ValidationRuleDataInterface[] $rules @return ValidationRuleDataInterface[]
entailment
public function retrieve(Model $model, $source) { if ($this->isTranslated()) { return $model->translations->pluck($source, config('translatable.locale_key', 'locale'))->toArray(); } return $this->resolveModelSource($model, $source); }
Retrieves current values from a model @param Model $model @param string $source @return mixed
entailment
public function store(Model $model, $source, $value) { if ( ! $this->isTranslated()) { $this->performStore($model, $source, $value); return; } /** @var Model|Translatable $model */ if ( ! is_array($value)) { throw new UnexpectedValueException("Va...
Stores a submitted value on a model @param Model $model @param string $source @param mixed $value
entailment
public function storeAfter(Model $model, $source, $value) { if ( ! $this->isTranslated()) { $this->performStoreAfter($model, $source, $value); return; } /** @var Model|Translatable $model */ if ( ! is_array($value)) { throw new UnexpectedValueExc...
Stores a submitted value on a model, after it has been created (or saved). @param Model $model @param mixed $source @param mixed $value
entailment
public function validationRules(ModelInformationInterface $modelInformation = null, $create) { if ( ! ($field = $this->formFieldData)) { return false; } return $this->getStrategySpecificRules($field); }
Returns validation rules to use for submitted form data for this strategy. If the return array is associative, rules are expected nested per key, otherwise the rules will be added to the top level key. @param ModelInformationInterface|ModelInformation|null $modelInformation @param bool ...
entailment
public function register() { $this->mergeConfigFrom( $this->getBasePath() . '/config/admin.php', 'admin' ); $this->registerMiddleware(); $this->registerFactory(); $this->app->instance('admin.instance', new Admin($this->app)); $this->app->bind(...
Register the application services. @return void
entailment
public function setTexts(string $active, string $inactive) { $this->texts = [$active, $inactive]; return $this; }
@param string $active @param string $inactive @return ElSwitch
entailment
public function setColors(string $active, string $inactive) { $this->colors = [$active, $inactive]; return $this; }
@param string $active @param string $inactive @return ElSwitch
entailment
public function setIconClasses(string $active, string $inactive) { $this->iconClasses = [$active, $inactive]; return $this; }
@param string $active @param string $inactive @return $this
entailment
protected function asDateTime($value) { if ($value instanceof Carbon) { return $value->timezone($this->getTimezone()); } if ($value instanceof \DateTimeInterface) { return new Carbon( $value->format('Y-m-d H:i:s.u'), $value->getTimezon...
Return a timestamp as DateTime object. @param mixed $value @return Carbon
entailment
public function fromDateTime($value) { return empty($value) ? $value : $this->asDateTime($value) ->timezone($this->getTimezone()) ->format($this->getFormat()); }
Convert a DateTime to a storable string. @param \DateTime|int $value @return string
entailment
public function mapWebRoutes(Router $router) { $permissionPrefix = $this->routeHelper->getPermissionPrefixForModelSlug( $this->getModelSlug() ); $router->group( [ 'prefix' => $this->getRoutePrefix(), 'as' => $this->getRouteNa...
Generates web routes for the module given a contextual router instance. Note that the module is responsible for ACL-checks, including route-based. @param Router $router
entailment
public function mapApiRoutes(Router $router) { $permissionPrefix = $this->routeHelper->getPermissionPrefixForModelSlug( $this->getModelSlug() ); $router->group( [ 'prefix' => $this->getRoutePrefix(), 'as' => $this->getRoute...
Generates API routes for the module given a contextual router instance. Note that the module is responsible for ACL-checks, including route-based. @param Router $router
entailment
public function getMenuPresence() { return [ 'id' => 'models.' . $this->getRouteSlug(), 'label' => ucfirst($this->getInformation()->labelPlural(false)), 'label_translated' => $this->getInformation()->labelPluralTranslationKey(), 'type'...
Returns data for CMS menu presence. @return null|array|MenuPresenceInterface[]|MenuPresenceInterface[]
entailment
public function render(Model $model, $source) { if (null === $this->resolveModelSource($model, $source)) { return ''; } return parent::render($model, $source); }
Renders a display value to print to the list view. @param Model $model @param mixed $source source column, method name or value @return string
entailment
public function handle(Request $request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { if ($request->expectsJson()) { return response()->json(Auth::user()); } return redirect()->route('admin.dashboard'); } return $ne...
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @param string|null $guard @return mixed
entailment
protected function getFileValidationRules() { $rules = array_get($this->field->options, 'validation', []); // If the 'image' rule is not set, make sure it is added. if (is_string($rules)) { if (empty($rules)) { $rules = 'image'; } elseif ( ! preg_matc...
Returns validation rules that should be applied to the uploaded file. @return string|array
entailment
public function setAutoSize($max, $min = 1) { $this->autoSize = [ 'minRows' => intval($min), 'maxRows' => intval($max), ]; return $this; }
@param int $max @param int $min @return $this
entailment
public function determineValidationRules(ModelAttributeData $attribute, ModelFormFieldData $field) { $rules = []; $required = $field->required(); switch ($attribute->cast) { case AttributeCast::BOOLEAN: $required = false; break; cas...
Determines validation rules for given attribute data. @param ModelAttributeData $attribute @param ModelFormFieldData $field @return array|false
entailment
protected function getValueFromRelationQuery($query) { // Query must be a relation in this case, since we need the related model if ( ! ($query instanceof Relation)) { throw new UnexpectedValueException("Query must be Relation instance for " . get_class($this)); } $relat...
Returns the value per relation for a given relation query builder. @param Builder|Relation $query @return mixed|null
entailment
public function performStoreAfter(Model $model, $source, $value) { $relation = $this->resolveModelSource($model, $source); if ( ! ($relation instanceof Relation)) { throw new UnexpectedValueException("{$source} did not resolve to relation"); } // Any singular relations ...
Stores a submitted value on a model, after it has been created (or saved). @param Model $model @param mixed $source @param mixed $value
entailment
protected function getModelsByKey($model, $keys) { if (is_string($model)) { $model = new $model; } /** @var Model $model */ return $model->withoutGlobalScopes() ->whereIn($model->getKeyName(), $keys) ->get() ->keyBy($model->getKeyName(...
Finds (to be related) models by their keys. @param string|Model $model @param array|Arrayable $keys @return Collection|Model[]
entailment
public function from(string $designDoc, string $name): ViewQuery { return ViewQuery::from($designDoc, $name); }
@param string $designDoc @param string $name @return ViewQuery
entailment
public function fromSpatial(string $designDoc, string $name): SpatialViewQuery { return ViewQuery::fromSpatial($designDoc, $name); }
@param string $designDoc @param string $name @return SpatialViewQuery
entailment