diff --git a/administrator/components/com_content/src/Model/ArticleModel.php b/administrator/components/com_content/src/Model/ArticleModel.php index 46f4bca0be414..d1afb7c2a141f 100644 --- a/administrator/components/com_content/src/Model/ArticleModel.php +++ b/administrator/components/com_content/src/Model/ArticleModel.php @@ -14,6 +14,7 @@ use Joomla\CMS\Event\AbstractEvent; use Joomla\CMS\Factory; use Joomla\CMS\Filter\InputFilter; +use Joomla\CMS\Form\Field\ListField; use Joomla\CMS\Form\Form; use Joomla\CMS\Form\FormFactoryInterface; use Joomla\CMS\Helper\TagsHelper; @@ -483,6 +484,15 @@ public function getForm($data = [], $loadData = true) $record->id = $id; + // Remove trashed option from state field for new article form + if ($id == 0) { + $field = $form->getField('state'); + + if ($field instanceof ListField) { + $field->removeOption(-2); + } + } + // For new articles we load the potential state + associations if ($id == 0 && $formField = $form->getField('catid')) { $assignedCatids = $data['catid'] ?? $form->getValue('catid'); diff --git a/libraries/src/Form/Field/ListField.php b/libraries/src/Form/Field/ListField.php index 138d89f4005bb..09d51ac18dad7 100644 --- a/libraries/src/Form/Field/ListField.php +++ b/libraries/src/Form/Field/ListField.php @@ -234,6 +234,27 @@ public function addOption($text, $attributes = []) return $this; } + /** + * Method to remove an option from list field. + * + * @param string $value The value of the option to remove + * + * @return static For chaining. + * + * @since __DEPLOY_VERSION__ + */ + public function removeOption(string $value): static + { + foreach ($this->element->option as $option) { + if ((string) $option['value'] === $value) { + $dom = dom_import_simplexml($option); + $dom->parentNode->removeChild($dom); + } + } + + return $this; + } + /** * Method to get certain otherwise inaccessible properties from the form field object. *