function pre_deleteItem() { global $DB; //remove field in container table if ($this->fields['type'] !== "header" && !isset($_SESSION['uninstall_fields']) && !isset($_SESSION['delete_container'])) { if ($this->fields['type'] === "dropdown") { $oldname = $this->fields['name']; $this->fields['name'] = getForeignKeyFieldForItemType(PluginFieldsDropdown::getClassname($this->fields['name'])); } $container_obj = new PluginFieldsContainer(); $container_obj->getFromDB($this->fields['plugin_fields_containers_id']); $classname = "PluginFields" . ucfirst(strtolower($container_obj->fields['itemtype'] . preg_replace('/s$/', '', $container_obj->fields['name']))); $classname::removeField($this->fields['name']); } if (isset($oldname)) { $this->fields['name'] = $oldname; } if ($this->fields['type'] === "dropdown") { return PluginFieldsDropdown::destroy($this->fields['name']); } return true; }
function pre_deleteItem() { global $DB; //TODO: remove labels translations //remove field in container table if ($this->fields['type'] !== "header" && !isset($_SESSION['uninstall_fields']) && !isset($_SESSION['delete_container'])) { if ($this->fields['type'] === "dropdown") { $oldname = $this->fields['name']; $this->fields['name'] = getForeignKeyFieldForItemType(PluginFieldsDropdown::getClassname($this->fields['name'])); } $container_obj = new PluginFieldsContainer(); $container_obj->getFromDB($this->fields['plugin_fields_containers_id']); foreach (json_decode($container_obj->fields['itemtypes']) as $itemtype) { $classname = "PluginFields" . ucfirst(strtolower($itemtype . preg_replace('/s$/', '', $container_obj->fields['name']))); $classname::removeField($this->fields['name']); } $classname::removeField($this->fields['name']); } //delete label translations $translation_obj = new PluginFieldsLabelTranslation(); $translations = $translation_obj->find("plugin_fields_itemtype = '" . self::getType() . "' AND plugin_fields_items_id = " . $this->fields['id']); foreach ($translations as $translation_id => $translation) { $translation_obj->delete(['id' => $translation_id]); } if (isset($oldname)) { $this->fields['name'] = $oldname; } if ($this->fields['type'] === "dropdown") { return PluginFieldsDropdown::destroy($this->fields['name']); } return true; }