* Adds the data of the pip entry with the given identifier into the
* given form and returns `true`. If no entry with the given identifier
* exists, `false` is returned.
- *
+ *
* @param string $identifier
* @param IFormDocument $document
* @return bool
return false;
}
- $data = [];
- /** @var \DOMNode $attribute */
- foreach ($element->attributes as $attribute) {
- $data[$attribute->nodeName] = $attribute->nodeValue;
- }
- foreach ($element->childNodes as $childNode) {
- if ($childNode instanceof \DOMText) {
- $data['__value'] = $childNode->nodeValue;
- }
- else {
- $data[$childNode->nodeName] = $childNode->nodeValue;
- }
- }
+ $data = $this->getElementData($element);
/** @var IFormNode $node */
foreach ($document->getIterator() as $node) {
if ($node instanceof IFormField && $node->isAvailable()) {
- $key = $node->getObjectProperty();
+ $key = $node->getId();
if (isset($data[$key])) {
$node->value($data[$key]);
}
+ else if ($node->getObjectProperty() !== $node->getId()) {
+ $key = $node->getObjectProperty();
+
+ if (isset($data[$key])) {
+ $node->value($data[$key]);
+ }
+ }
}
}
$className = $element->getElementsByTagName('classname')->item(0);
if ($className) {
- $data['classname'] = $className->nodeValue;
+ $data['className'] = $className->nodeValue;
}
$additionalData = [];
$list->readObjects();
foreach ($list as $definition) {
- $this->definitionNames[$definition->definitionName] = $definition->definitionName;
+ $this->definitionNames[$definition->definitionID] = $definition->definitionName;
if ($definition->interfaceName) {
- $this->definitionNamesWithInterface[$definition->definitionName] = $definition->interfaceName;
+ $this->definitionNamesWithInterface[$definition->definitionID] = $definition->interfaceName;
}
}
// add default form fields
$form->getNodeById('data')->appendChildren([
- SingleSelectionFormField::create('definitionName')
- ->objectProperty('definitionname')
+ SingleSelectionFormField::create('definitionID')
->label('wcf.acp.pip.objectType.definitionName')
->description('<!-- will be replaced by JavaScript -->')
->options($this->definitionNames)
->required()
->addValidator(self::getObjectTypeAlikeValueValidator('wcf.acp.pip.objectType.objectType'))
->addValidator(new FormFieldValidator('uniqueness', function(TextFormField $formField) {
- $definitionName = $formField->getDocument()->getNodeById('definitionName')->getValue();
- if ($definitionName) {
+ $definitionID = $formField->getDocument()->getNodeById('definitionID')->getValue();
+ if ($definitionID) {
+ $definition = ObjectTypeCache::getInstance()->getDefinition($definitionID);
+
$objectType = ObjectTypeCache::getInstance()->getObjectTypeByName(
- ObjectTypeCache::getInstance()->getDefinitionByName($definitionName)->definitionName,
+ $definition->definitionName,
$formField->getValue()
);
if ($objectType !== null && (
$formField->getDocument()->getFormMode() === IFormDocument::FORM_MODE_CREATE ||
$this->editedEntry->getElementsByTagName('name')->item(0)->nodeValue !== $formField->getValue() ||
- $this->editedEntry->getElementsByTagName('definitionname')->item(0)->nodeValue !== $definitionName
+ $this->editedEntry->getElementsByTagName('definitionname')->item(0)->nodeValue !== $definition->definitionName
)) {
$formField->addValidationError(
new FormFieldValidationError(
->description('<!-- will be replaced by JavaScript -->')
->required()
->addValidator(new FormFieldValidator('implementsInterface', function(TextFormField $formField) {
- $definitionName = $formField->getDocument()->getNodeById('definitionName')->getValue();
- if ($definitionName) {
- $definition = ObjectTypeCache::getInstance()->getDefinitionByName($definitionName);
+ $definitionID = $formField->getDocument()->getNodeById('definitionID')->getValue();
+ if ($definitionID) {
+ $definition = ObjectTypeCache::getInstance()->getDefinition($definitionID);
if (!is_subclass_of($formField->getValue(), $definition->interfaceName)) {
$formField->addValidationError(
]);
/** @var SingleSelectionFormField $definitionName */
- $definitionName = $form->getNodeById('definitionName');
+ $definitionID = $form->getNodeById('definitionID');
// add general field dependencies
$form->getNodeById('className')->addDependency(
- ValueFormFieldDependency::create('definitionName')
- ->field($definitionName)
+ ValueFormFieldDependency::create('definitionID')
+ ->field($definitionID)
->values(array_keys($this->definitionNamesWithInterface))
);
*/
public function getObjectTypeDefinitionDataContainer(IFormDocument $form, string $definitionName): FormContainer {
/** @var SingleSelectionFormField $definitionNameField */
- $definitionNameField = $form->getNodeById('definitionName');
+ $definitionIDField = $form->getNodeById('definitionID');
$definitionPieces = explode('.', $definitionName);
$formContainer = FormContainer::create(lcfirst(implode('', array_map('ucfirst', $definitionPieces))) . 'Fields')
->label('wcf.acp.pip.objectType.' . $definitionName . '.data.title')
->addDependency(
- ValueFormFieldDependency::create('definitionName')
- ->field($definitionNameField)
+ ValueFormFieldDependency::create('definitionID')
+ ->field($definitionIDField)
->values([$definitionName])
);
protected function writeEntry(\DOMDocument $document, IFormDocument $form): \DOMElement {
$type = $document->createElement('type');
foreach ($form->getData()['data'] as $key => $value) {
+ if ($key === 'definitionID') {
+ $key = 'definitionname';
+ $value = ObjectTypeCache::getInstance()->getDefinition($value)->definitionName;
+ }
+
if ($value !== '') {
if (is_string($value)) {
$type->appendChild($document->createElement($key, $this->getAutoCdataValue($value)));