/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/View/Form
NameSizeModeActions
ArrayContext.php108880644editdlrm
ContextFactory.php54470644editdlrm
ContextInterface.php43010644editdlrm
EntityContext.php232570644editdlrm
FormContext.php58220644editdlrm
NullContext.php27750644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/cakephp/src/View/Form/FormContext.php (5822B)
_form = $context['entity']; $this->_validator = $context['validator'] ?? null; } /** * Get the fields used in the context as a primary key. * * @return array * @deprecated 4.0.0 Renamed to {@link getPrimaryKey()}. */ public function primaryKey(): array { deprecationWarning('`FormContext::primaryKey()` is deprecated. Use `FormContext::getPrimaryKey()`.'); return []; } /** * @inheritDoc */ public function getPrimaryKey(): array { return []; } /** * @inheritDoc */ public function isPrimaryKey(string $field): bool { return false; } /** * @inheritDoc */ public function isCreate(): bool { return true; } /** * @inheritDoc */ public function val(string $field, array $options = []) { $options += [ 'default' => null, 'schemaDefault' => true, ]; $val = $this->_form->getData($field); if ($val !== null) { return $val; } if ($options['default'] !== null || !$options['schemaDefault']) { return $options['default']; } return $this->_schemaDefault($field); } /** * Get default value from form schema for given field. * * @param string $field Field name. * @return mixed */ protected function _schemaDefault(string $field) { $field = $this->_form->getSchema()->field($field); if ($field) { return $field['default']; } return null; } /** * @inheritDoc */ public function isRequired(string $field): ?bool { $validator = $this->_form->getValidator($this->_validator); if (!$validator->hasField($field)) { return null; } if ($this->type($field) !== 'boolean') { return !$validator->isEmptyAllowed($field, $this->isCreate()); } return false; } /** * @inheritDoc */ public function getRequiredMessage(string $field): ?string { $parts = explode('.', $field); $validator = $this->_form->getValidator($this->_validator); $fieldName = array_pop($parts); if (!$validator->hasField($fieldName)) { return null; } $ruleset = $validator->field($fieldName); if (!$ruleset->isEmptyAllowed()) { return $validator->getNotEmptyMessage($fieldName); } return null; } /** * @inheritDoc */ public function getMaxLength(string $field): ?int { $validator = $this->_form->getValidator($this->_validator); if (!$validator->hasField($field)) { return null; } foreach ($validator->field($field)->rules() as $rule) { if ($rule->get('rule') === 'maxLength') { return $rule->get('pass')[0]; } } $attributes = $this->attributes($field); if (!empty($attributes['length'])) { return $attributes['length']; } return null; } /** * @inheritDoc */ public function fieldNames(): array { return $this->_form->getSchema()->fields(); } /** * @inheritDoc */ public function type(string $field): ?string { return $this->_form->getSchema()->fieldType($field); } /** * @inheritDoc */ public function attributes(string $field): array { return array_intersect_key( (array)$this->_form->getSchema()->field($field), array_flip(static::VALID_ATTRIBUTES) ); } /** * @inheritDoc */ public function hasError(string $field): bool { $errors = $this->error($field); return count($errors) > 0; } /** * @inheritDoc */ public function error(string $field): array { return (array)Hash::get($this->_form->getErrors(), $field, []); } }