Skip to content
Closed
10 changes: 10 additions & 0 deletions administrator/components/com_content/src/Model/ArticleModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
21 changes: 21 additions & 0 deletions libraries/src/Form/Field/ListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down