protected function validateMetas(Node $node, Node $obj, NodeSchema $schema, $mode) { $processed_metas = array(); $metas = $obj->getMetas(); // Check all metas passed against the meta defs. foreach ($metas as $meta) { // Ensure the meta has a meta_def $meta_def = $schema->getMetaDef($meta->getMetaName()); $this->getErrors()->rejectIfInvalid($this->resolveField($node->getNodeRef(), $meta->getMetaName(), $obj instanceof Section ? $obj : null), 'meta', $meta_def->Title, $meta->getValue(), $meta_def->Validation); $processed_metas[] = $meta->getMetaName(); } $meta_defs = $schema->getMetaDefs(); // Check all meta defs that haven't been processed // These meta defs must only match partials that we have. $meta_partials = PartialUtils::unserializeMetaPartials($node->getNodePartials()->getMetaPartials()); $re_meta_partials = PartialUtils::unserializeMetaPartials($node->getNodePartials()->getRestrictedMetaPartials()); foreach ($meta_defs as $meta_def) { if (in_array($meta_def->Id, $processed_metas)) { continue; } if ($mode == 'edit' && !$this->metaInScope($schema, new Meta($meta_def->Id, ''), $meta_partials, $re_meta_partials)) { continue; } // Validate the meta def with a null value $this->getErrors()->rejectIfInvalid($this->resolveField($node->getNodeRef(), $meta_def->Id, $obj instanceof Section ? $obj : null), 'meta', $meta_def->Title, null, $meta_def->Validation); $processed_metas[] = $meta_def->Id; } }
public static function isMetaInScope(NodeSchema $schema, NodePartials $nodePartials, $id) { $partials = self::unserializeMetaPartials($nodePartials->getMetaPartials()); $re_partials = self::unserializeMetaPartials($nodePartials->getRestrictedMetaPartials()); $id = strtolower(ltrim($id, '#')); foreach ((array) $re_partials as $partial) { if ($partial->getMetaName() == $id) { return false; } } if ($partials == 'all') { return true; } // will throw Exception is schema def doesn't exist try { $schema->getMetaDef($id); } catch (SchemaException $se) { return false; } $inScope = false; foreach ($partials as $partial) { if ($partial->getMetaName() == $id) { $inScope = true; break; } } if (!$inScope) { return false; } return true; }
protected function convertMeta(Node $node, NodeSchema &$schema, Errors &$errors, $name, $value, $rawValue) { $meta_def = $schema->getMetaDef($name); $validation = $meta_def->Validation->getValidationArray(); $key = $meta_def->Id; $fieldTitle = $meta_def->Title; try { $value = $this->TypeConverter->convertFromString($meta_def->Validation, $value, $rawValue); } catch (TypeConversionException $tce) { $errors->addFieldError('invalid', $this->NodeValidator->resolveField($node->getNodeRef(), $key), 'field', $fieldTitle, $value, $tce->getMessage()); } return $value; }