admin管理员组

文章数量:1393880

When someone adds an external link in Wagtail CMS, they should have the option to choose whether to make the link 'nofollow' or 'noreferrer.' To achieve this, I have inherited the existing link form, and the code is provided here

class CustomExternalLinkChooserForm(ExternalLinkChooserForm):

rel = forms.ChoiceField(
    choices=[
        ("noreferrer", "Noreferrer"),
        ("nofollow", "Nofollow"),
    ],
    required=False,
    label=_("Rel Attribute"),
)

i have also inherited view

class CustomExternalLinkView(ExternalLinkView):

form_class = CustomExternalLinkChooserForm

i registered this in wagtail hooks so admin take this override core view

@hooks.register("register_admin_urls")
def register_custom_external_link_view():

return [
    path(
        "admin/choose-external-link/",
        CustomExternalLinkView.as_view(),
        name="wagtailadmin_choose_page_external_link",
    )
]

By using the above, it gives me an output like this, but the main issue is that when the Draftail rich text editor saves the link in the database, it does not add the rel attribute in href url. How can I solve this issue?

When someone adds an external link in Wagtail CMS, they should have the option to choose whether to make the link 'nofollow' or 'noreferrer.' To achieve this, I have inherited the existing link form, and the code is provided here

class CustomExternalLinkChooserForm(ExternalLinkChooserForm):

rel = forms.ChoiceField(
    choices=[
        ("noreferrer", "Noreferrer"),
        ("nofollow", "Nofollow"),
    ],
    required=False,
    label=_("Rel Attribute"),
)

i have also inherited view

class CustomExternalLinkView(ExternalLinkView):

form_class = CustomExternalLinkChooserForm

i registered this in wagtail hooks so admin take this override core view

@hooks.register("register_admin_urls")
def register_custom_external_link_view():

return [
    path(
        "admin/choose-external-link/",
        CustomExternalLinkView.as_view(),
        name="wagtailadmin_choose_page_external_link",
    )
]

By using the above, it gives me an output like this, but the main issue is that when the Draftail rich text editor saves the link in the database, it does not add the rel attribute in href url. How can I solve this issue?

Share Improve this question asked Mar 27 at 14:07 Dhruvin KalathiyaDhruvin Kalathiya 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You will also need to customize the LinkHandlers. There is an example in the docs for how to add nofollow to all links. You will need to modify it to accept your dynamic attribute. https://docs.wagtail./en/stable/extending/rich_text_internals.html#registering-rewrite-handlers

本文标签: djangoHow can i edit external link format converter rule in wagtail cms draftail editorStack Overflow