/** * Run the configured resource's inspection checks and show the result, if necessary * * This will only run any validation if the user pushed the 'resource_validation' button. * * @param array $formData * * @return bool */ public function isValidPartial(array $formData) { if ($this->getElement('resource_validation')->isChecked() && parent::isValid($formData)) { $inspection = static::inspectResource($this); if ($inspection !== null) { $join = function ($e) use(&$join) { return is_string($e) ? $e : join("\n", array_map($join, $e)); }; $this->addElement('note', 'inspection_output', array('order' => 0, 'value' => '<strong>' . $this->translate('Validation Log') . "</strong>\n\n" . join("\n", array_map($join, $inspection->toArray())), 'decorators' => array('ViewHelper', array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output'))))); if ($inspection->hasError()) { $this->warning(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $inspection->getError())); return false; } } $this->info($this->translate('The configuration has been successfully validated.')); } return true; }
/** * Return whether the given values are valid * * @param array $formData The data to validate * * @return bool */ public function isValid($formData) { if (!parent::isValid($formData)) { return false; } if (($el = $this->getElement('skip_validation')) === null || false === $el->isChecked()) { $resourceConfig = ResourceFactory::getResourceConfig($this->getValue('resource')); if (!self::isValidIdoSchema($this, $resourceConfig) || !self::isValidIdoInstance($this, $resourceConfig)) { if ($el === null) { $this->addSkipValidationCheckbox(); } return false; } } return true; }
/** * {@inheritdoc} */ public function isValid($formData) { if (!parent::isValid($formData)) { return false; } $valid = true; if (isset($formData['users']) && $formData['users']) { $parsedUserRestrictions = array(); foreach (Auth::getInstance()->getRestrictions('application/share/users') as $userRestriction) { $parsedUserRestrictions[] = array_map('trim', explode(',', $userRestriction)); } if (!empty($parsedUserRestrictions)) { $desiredUsers = array_map('trim', explode(',', $formData['users'])); array_unshift($parsedUserRestrictions, $desiredUsers); $forbiddenUsers = call_user_func_array('array_diff', $parsedUserRestrictions); if (!empty($forbiddenUsers)) { $valid = false; $this->getElement('users')->addError($this->translate(sprintf('You are not permitted to share this navigation item with the following users: %s', implode(', ', $forbiddenUsers)))); } } } if (isset($formData['groups']) && $formData['groups']) { $parsedGroupRestrictions = array(); foreach (Auth::getInstance()->getRestrictions('application/share/groups') as $groupRestriction) { $parsedGroupRestrictions[] = array_map('trim', explode(',', $groupRestriction)); } if (!empty($parsedGroupRestrictions)) { $desiredGroups = array_map('trim', explode(',', $formData['groups'])); array_unshift($parsedGroupRestrictions, $desiredGroups); $forbiddenGroups = call_user_func_array('array_diff', $parsedGroupRestrictions); if (!empty($forbiddenGroups)) { $valid = false; $this->getElement('groups')->addError($this->translate(sprintf('You are not permitted to share this navigation item with the following groups: %s', implode(', ', $forbiddenGroups)))); } } } return $valid; }
/** * Return whether the given values are valid * * @param array $formData The data to validate * * @return bool */ public function isValid($formData) { if (!parent::isValid($formData)) { return false; } $resourceConfig = ResourceFactory::getResourceConfig($this->getValue('resource')); if (!self::isValidIdoSchema($this, $resourceConfig) || !self::isValidIdoInstance($this, $resourceConfig)) { $this->addSkipValidationCheckbox(); return false; } return true; }