Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dsenalik
Copy link
Contributor

@dsenalik dsenalik commented Oct 14, 2024

Bug Fix

Closes #1996

Depends on #2001 (merged)

Tripal Version: 4.x

Description

The current default URL template [type]/[TripalEntity__entity_id] is not valid when you create a new custom content type.
This PR does two things

  1. Change the default URL template to [TripalBundle__bundle_id]/[TripalEntity__entity_id], which will now work as expected.
  2. Adds two more tokens [TripalEntityType__term_namespace] and [TripalEntityType__term_accession]

Testing?

  1. Create a new content type. I used "Primer" based on the "feature" table. However I would recommend a two-word type to test something with spaces, i.e. "Oligonucleotide Primer" would be great. For example
    PR2002finishedprimer
  2. You can go ahead and add the required fields for a content type based on the feature table: name, uniquename, organism, type_reference
  3. Create the required organism
  4. Create a primer entity and confirm that the url alias is, in this case, oligonucleotide_primer/2

@dsenalik dsenalik added Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields. Easy PR Review 😀 Small easy to review pull request labels Oct 14, 2024
Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as described ✅

However, it is a bit disorienting for the URL scheme to change without telling the user. Especially as it's hidden in a vertical tabs so on editing you would only notice if you open it up.

Instead, perhaps we should just add some more tokens:

  • [TripalEntityType__term_name]
  • [TripalEntityType__term_accession]
  • [TripalEntityType__machine_name]

Then the URL schema can be [TripalEntityType__term_name]/[TripalEntity__entity_id] right off the bat without any worry of it not existing yet and no need to change it.

This would be done by adding the tokens like this: https://github.com/tripal/tripal/blob/4.x/tripal/src/Entity/TripalEntityType.php#L550-L558

And then updating the parser to handle theme here: https://github.com/tripal/tripal/blob/4.x/tripal/src/Services/TripalTokenParser.php#L222-L234

@dsenalik
Copy link
Contributor Author

dsenalik commented Oct 21, 2024

So it turns out that the token that we need for this already exists, it is the [TripalBundle__bundle_id] one.

Well, since I am in here anyway, I did add two new tokens [TripalEntityType__term_namespace] and [TripalEntityType__term_accession] but I did not implement the machine name one, mainly because I don't know what it is supposed to be 😐.
PR2002_url_format

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope you're ok with me making a few changes @dsenalik? If not, feel free to revert or change :-)

Specifically, I

  • fixed an inconsistency between [TripalBundle__bundle_id] and [TripalEntityType__label] which both refer to TripalContent Type and thus should use the same naming convention. See commit b9ab7b1
  • Expanded descriptions to make each token more clear. The [TripalBundle__bundle_id] token is actually the machine name I referred to. I'm guessing the difference was not clear because we often use the the term name as the content type label. See my screenshots below to see the difference.
  • Added a [TripalEntityType__term_label] token to be the cvterm.name / term name that we intended to be included in the default token.
  • Moved the new tokens added by this PR out of the 'include id' if block since they are not IDs and thus should be available for use in the title.

Now when I test creating a new content type I see the new default URL template (shown here on edit since I didn't save my create screenshot 🤦 )
image

And when I create a primer page, I see the token is replaced properly:
Screenshot 2024-10-22 at 11 34 57 AM

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did notice another issue though 🙈 I don't think this is new to this PR but it was aggravated by it. Specifically, if you try to create a new content type right now, the title format will fail validation. Technically that is because it has now gotten too long but more problematically, it is because we have no fields yet and therefore the default title pattern just includes all non-field tokens which A) is too long and B) is not unique 🙈 🫢

@dsenalik
Copy link
Contributor Author

  • Moved the new tokens added by this PR out of the 'include id' if block since they are not IDs and thus should be available for use in the title.

The reason I did that, keep them in the include id test, was because otherwise they got added to the default title and it was a mess. As you have noted this causes problems.

@laceysanderson
Copy link
Member

Moved the new tokens added by this PR out of the 'include id' if block since they are not IDs and thus should be available for use in the title.

The reason I did that, keep them in the include id test, was because otherwise they got added to the default title and it was a mess. As you have noted this causes problems.

Ahhhh... I see. But they should be available 🙈 It sounds like we need to create a new issue for the title format when there are no fields. For now, I can add them back into an if block with a todo to remove once the title format issue is resolved.

Sound good?

@dsenalik
Copy link
Contributor Author

That would be okay. Or alternatively we could remove the new tokens entirely for now, and add them back with a title fix.
This would make this into a 1-line PR for now

@dsenalik
Copy link
Contributor Author

Well, you worked on the descriptions, so let's keep them

@laceysanderson
Copy link
Member

That would be okay. Or alternatively we could remove the new tokens entirely for now, and add them back with a title fix.

This would make this into a 1-line PR for now

We need the term_label token. The original bundle_id token you used is the machine name not the term. That's why I fixed the descriptions ;-p

Ok, I will add the commit and make the new issue.

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now described in issue #2009 and the change is made allowing the title to continue quietly being a problem 🙈

image

Can you give this a try @dsenalik to confirm it works on your end just to make sure? I approve the current state of the code.

@dsenalik
Copy link
Contributor Author

It is working as desired.
I tried pushing the boundaries, using terms with spaces to define the content type, such as "INR motif" and this works just fine
http://localhost:8096/INR_motif/4
Editing the title format before creating the entity gives expected result.
Failing to edit it gives every entity the same name as the bundle, again as expected.

@laceysanderson
Copy link
Member

Thanks for the confirmation @dsenalik and for all the work on this!

@laceysanderson laceysanderson merged commit 420d61d into 4.x Oct 22, 2024
15 checks passed
@laceysanderson laceysanderson deleted the tv4g1-issue1996-fix-url-template branch October 22, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Easy PR Review 😀 Small easy to review pull request Group 1 - Tripal Content Types | Terms | Fields Any issue relating to Tripal Content including types, terms, and fields.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid URL template when creating a new content type through the UI

2 participants