Skip to content

Commit

Permalink
Quick: Fix Support for Unadulterated Link Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyboar committed Aug 31, 2021
1 parent 9cf1e67 commit 9d018e0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions taccsite_cms/contrib/bootstrap4_djangocms_link/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@
# FAQ: If we can import both plugins, then re-register LinkPlugin
# (because Bootstrap4Link unregistered LinkPlugin)
try:
import copy

from cms.plugin_pool import plugin_pool

from djangocms_link.cms_plugins import LinkPlugin
from djangocms_bootstrap4.contrib.bootstrap4_link.cms_plugins import Bootstrap4LinkPlugin

# Restore original fields
# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/2.0.0/djangocms_bootstrap4/contrib/bootstrap4_link/cms_plugins.py#L26-L42
# SEE: https://github.com/django-cms/djangocms-link/blob/3.0.0/djangocms_link/cms_plugins.py#L20-L23
LinkPlugin.fieldsets[0][1]['fields'] = (
'name',
('external_link', 'internal_link'),
# To unlink Bootstrap's plugin fieldsets from generic Link's
# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/2.0.0/djangocms_bootstrap4/contrib/bootstrap4_link/cms_plugins.py#L44
Bootstrap4LinkPlugin.fieldsets = copy.deepcopy(Bootstrap4LinkPlugin.fieldsets)

# To restore generic Link plugin fieldsets to state before Bootstrap's
# SEE: https://github.com/django-cms/djangocms-link/blob/3.0.0/djangocms_link/cms_plugins.py#L19-L24
# SEE: https://github.com/django-cms/djangocms-bootstrap4/blob/2.0.0/djangocms_bootstrap4/contrib/bootstrap4_link/cms_plugins.py#L38-L42
LinkPlugin.fieldsets[0] = (
None, {
'fields': (
'name',
('external_link', 'internal_link'),
)
}
)

# To re-register generic Link plugin
# SEE: https://github.com/django-cms/djangocms-link/issues/163
# SEE: https://github.com/django-cms/djangocms-link/issues/167
plugin_pool.register_plugin(LinkPlugin)

# CAVEAT: If import statement fails for reason other than Bootstrap presence,
# then that failure, and the failure of this plugin, is silent
except ImportError:
Expand Down

0 comments on commit 9d018e0

Please sign in to comment.