Skip to content

Commit

Permalink
fix(entityconfig): enhance lazy creation of entity config
Browse files Browse the repository at this point in the history
btry committed Feb 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1e7fb3a commit 7297624
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions inc/entityconfig.class.php
Original file line number Diff line number Diff line change
@@ -148,6 +148,9 @@ public function prepareInputForAdd($input) {
}

public function prepareInputForUpdate($input) {
// Disallow changing the linked entity
unset($input['entities_id']);

$input['header'] = $input['header'] ?? '';

$config = Toolbox::getHtmLawedSafeConfig();
@@ -156,22 +159,31 @@ public function prepareInputForUpdate($input) {
return $input;
}

protected static function createDefaultsForEntity($entityId): self {
$entityConfig = new self();
if ($entityConfig->getFromDbByCrit(['entities_id' => $entityId])) {
return $entityConfig;
}

$entityConfig->add([
'entities_id' => $entityId,
'replace_helpdesk' => self::CONFIG_PARENT,
'is_kb_separated' => self::CONFIG_PARENT,
'is_search_visible' => self::CONFIG_PARENT,
'is_header_visible' => self::CONFIG_PARENT,
'sort_order' => self::CONFIG_PARENT,
]);

return $entityConfig;
}

public function showFormForEntity(Entity $entity) {
$ID = $entity->getField('id');
$ID = $entity->getID();
if (!$entity->can($ID, READ)) {
return false;
}

if (!$this->getFromDbByCrit(['entities_id' => $ID])) {
$this->add([
'entities_id' => $ID,
'replace_helpdesk' => self::CONFIG_PARENT,
'is_kb_separated' => self::CONFIG_PARENT,
'is_search_visible' => self::CONFIG_PARENT,
'is_header_visible' => self::CONFIG_PARENT,
'sort_order' => self::CONFIG_PARENT,
]);
}
$this->getFromDB(self::createDefaultsForEntity($ID)->getID());

$canedit = Entity::canUpdate() && $entity->canUpdateItem();
echo "<div class='spaced'>";
@@ -389,6 +401,7 @@ static function getUsedConfig($fieldref, $entities_id, $fieldval = '', $default_
// Search in entity data of the current entity
if ($entity->getFromDB($entities_id)) {
// Value is defined : use it
self::createDefaultsForEntity($entities_id);
if ($entityConfig->getFromDBByCrit(['entities_id' => $entities_id])) {
if (is_numeric($default_value)
&& ($entityConfig->fields[$fieldref] != self::CONFIG_PARENT)) {

0 comments on commit 7297624

Please sign in to comment.