PR-5.2-dev Pending

User tests: Successful: 2 brianteeman, joomdonation Unsuccessful: 0

avatar reem-atalah
reem-atalah
4 Mar 2025

Pull Request for Issue #44962.

Summary of Changes

Remove the "Trashed" option from the "Status" drop-down list in the New article form.

Testing Instructions

Log in to Joomla! administrator
Toogle Menu -> Content -> Articles
Click on the "New" button
Click on the "Status" Drop down list
You will not see "Trashed" option

Actual result BEFORE applying this Pull Request

The trashed option appears in the status on the new article page
image

Expected result AFTER applying this Pull Request

The trashed option doesn't appear in the status on the new article page
image

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar reem-atalah reem-atalah - open - 4 Mar 2025
avatar reem-atalah reem-atalah - change - 4 Mar 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 4 Mar 2025
Category Administration com_content
avatar reem-atalah reem-atalah - change - 4 Mar 2025
Title
44962: remove trashed status from new article page
[5.2] 44962: remove trashed status from new article page
avatar reem-atalah reem-atalah - edited - 4 Mar 2025
avatar brianteeman
brianteeman - comment - 4 Mar 2025

Can you still change an article to be trashed?

avatar charvimehradu
charvimehradu - comment - 4 Mar 2025

hi,
the problem with this would be when we actually trash an article, the status would be shown as published (the default) and there would be no option to change the status of the article from the screen of the article. same as @brianteeman asked.

avatar brianteeman brianteeman - test_item - 4 Mar 2025 - Tested unsuccessfully
avatar brianteeman
brianteeman - comment - 4 Mar 2025

I have tested this item 🔴 unsuccessfully on 69c322d


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45065.

avatar reem-atalah
reem-atalah - comment - 4 Mar 2025

Can you still change an article to be trashed?

yes
Screenshot from 2025-03-04 18-17-23
Screenshot from 2025-03-04 18-17-37
Screenshot from 2025-03-04 18-17-58

avatar reem-atalah
reem-atalah - comment - 4 Mar 2025

hi, the problem with this would be when we actually trash an article, the status would be shown as published (the default). same as @brianteeman asked.

Yes you're right thanks for highlighting this, I'll see it again

avatar reem-atalah
reem-atalah - comment - 4 Mar 2025

I have tested this item 🔴 unsuccessfully on 69c322d

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45065.

Can you give me more information

avatar brianteeman
brianteeman - comment - 4 Mar 2025

@reem-atalah i marked it as unsuccessful as the issue you are fixing is not to offer trashed as an option when creating a NEW article but what you have done is to remove the ability to mark ANY article as trashed.

avatar fgsw fgsw - test_item - 4 Mar 2025 - Tested unsuccessfully
avatar fgsw
fgsw - comment - 4 Mar 2025

I have tested this item 🔴 unsuccessfully on 69c322d

With Without
Untitled-pr Untitled

Issue #44962 was about new/unsaved articles. Now in saved articles is no Trashedpossible.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45065.
avatar reem-atalah
reem-atalah - comment - 4 Mar 2025

Yes I'll handle this now
Appreciated your testing and feedback

avatar reem-atalah reem-atalah - change - 4 Mar 2025
Labels Added: PR-5.2-dev
avatar reem-atalah
reem-atalah - comment - 4 Mar 2025

@brianteeman @fgsw Hi, I have edited the code and tested it to ensure that all article pages except the new article page have the "Trashed" option.
I appreciate your testing again, thanks in advance.

avatar brianteeman
brianteeman - comment - 4 Mar 2025

This is looking more promising.

We do not add scripts inline like this. You should make it a standalone script and then it can also be used in all similar forms not just the admin content form.

I am not the best person to guide you on this but if you read https://manual.joomla.org/docs/general-concepts/javascript/adding-javascript/ it should point you in the right direction

avatar reem-atalah
reem-atalah - comment - 4 Mar 2025

Ok I'll see it, thanks for directing me

avatar reem-atalah
reem-atalah - comment - 4 Mar 2025

I can see that the scripts are set in one place which is Joomla-cms/media/com_content/js (in the case of the articles)
But the Media folder is not part of the Joomla-cms repo, it's a library, I have searched in the composer.json, and found "Joomla/MediaWiki", when I opened this repo I didn't find the Media folders, as seen in the Joomla-cms, so it's not the correct place. It's also not mentioned in the link you gave me before. Any clue to find the right place to update in the Media folder to add my js file?

avatar joomdonation
joomdonation - comment - 5 Mar 2025

You can see source code of our JS in media_source folder. However, what you are doing here in this PR is not the right approach.

For adjusting a form, we should modify code of getForm method to make any adjustment. That would require understand our Form API

For this PR, below are how I would work on:

  • We need to remove an option from a ListField, so I first add a method to ListField class to allow removing an option base on the value. The method should be added after addOption method
  • Then modify code in getForm method of ArticleModel which I mentioned earlier, call $form->getField('state') to get the state field and then call the removeOption method which is added in earlier step to remove the option (in case $id = 0, for new article).
avatar fgsw
fgsw - comment - 5 Mar 2025

@reem-atalah Can you change the title (without the issue-number) because the title is used in the changelog.

avatar reem-atalah reem-atalah - change - 5 Mar 2025
Title
[5.2] 44962: remove trashed status from new article page
[5.2] remove trashed status from new article page
avatar reem-atalah reem-atalah - edited - 5 Mar 2025
avatar reem-atalah
reem-atalah - comment - 5 Mar 2025

@joomdonation Thanks a lot for directing me, I'll consider it. Appreciated

avatar joomla-cms-bot joomla-cms-bot - change - 5 Mar 2025
Category Administration com_content Administration com_content Libraries
avatar reem-atalah
reem-atalah - comment - 5 Mar 2025

@joomdonation @brianteeman @fgsw I updated the PR, I hope it's now as expected, and be able to be merged

avatar brianteeman
brianteeman - comment - 5 Mar 2025

If you set the article option to use workflow and then try to create or edit an article you get the error

0 Call to undefined method Joomla\CMS\Form\Field\SpacerField::removeTrashedOption()

image

avatar reem-atalah
reem-atalah - comment - 5 Mar 2025

I can see that SpacerField, ListField, etc. (if there's another) are inherited from FormField, and I think this is the centralized place. Now it works, if there is another case that I can't see please inform me

avatar joomdonation
joomdonation - comment - 5 Mar 2025

@reem-atalah Not all FormField has option, so it does not make sense to add that method to FormField class. Please follow instructions below:

  1. Add this method to ListField class as I mentioned before
/**
 * 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;
}
  1. Then in getForm method of ArticleModel, add the code below:
// Remove trashed option from state field for new article form
if ($id == 0)
{
	$field = $form->getField('state');

	if ($field !== false && $field->type === 'List')
	{
		$field->removeOption(-2);
	}
}

Hope you get the idea. Instead of add method to remove trashed option, the method would allow removing any options with the given value instead. And then in the model, you call $field->removeOption('-2') to remove the trashed option from the field

avatar reem-atalah
reem-atalah - comment - 5 Mar 2025

Ok, I thought this would be needed in all FormField, but yes I got how you want to proceed with the logic. Pretty to have the method more generic with an input, I can think of this after revising the code. Thanks for the clarification.

avatar reem-atalah
reem-atalah - comment - 5 Mar 2025

Updated, I hope now it fits our case

avatar brianteeman brianteeman - test_item - 5 Mar 2025 - Tested successfully
avatar brianteeman
brianteeman - comment - 5 Mar 2025

I have tested this item ✅ successfully on e9b313a

does what it says -= thanks

maintainers - should this be added to all other new forms (both site and admin)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45065.

avatar reem-atalah
reem-atalah - comment - 6 Mar 2025

Hello @brianteeman thanks for testing, Can I know what's next so my code can be merged?

avatar joomdonation joomdonation - test_item - 6 Mar 2025 - Tested successfully
avatar joomdonation
joomdonation - comment - 6 Mar 2025

I have tested this item ✅ successfully on e9b313a


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45065.

avatar joomdonation joomdonation - change - 6 Mar 2025
Status Pending Ready to Commit
avatar joomdonation
joomdonation - comment - 6 Mar 2025

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45065.

avatar joomdonation
joomdonation - comment - 6 Mar 2025

@reem-atalah The PR is now RTC. We will just need to wait for maintainer to review and merge it.

avatar reem-atalah
reem-atalah - comment - 6 Mar 2025

@joomdonation Great, thanks for the clarification.

Add a Comment

Login with GitHub to post a comment