This is a sort of meta issue, as it's more about what the plan is. Background:

I've created a custom Aloha plugin for inserting a 'semantic headline' in Aloha. It's just a simple token ala [subheadline:Text], which gets rendered as the appropriate tag in the editor, and later by an input filter. It's the simplest of plugins we're planning for a large project.

Mirroring how the Aloha module takes a que from the configured filters regarding which tags to allow, I thought it would be appropriate to configure the tag used for the semantic headlines on the input filter. Different text formats might specify different tags, and having the setup in the text format seems logical.

There's two parts to getting the setting to the plugin: 1: getting the setting linked up with the textarea/format. 2: getting it from 1 to the plugin.

As to 1: Adding another hook_prerender_text_format() that adds plugin specific settings to the settings array for each textareas aloha per-text-format settings is doable, but fragile (starting out with if (!empty($element['format']['format']['#attached']['js'][0]['data']['aloha']['textareas'])) doesn't bode well). Implementing a hook that allows modules to add in extra settings would be easy, but I'm not sure why it's unnecessary to duplicate the per text format settings per textarea? The same text format on any textarea, would have the same settings, no? Shouldn't the text format settings not just list the available formats for this textarea, and use a global configuration for text format settings for Aloha?

Regarding 2, I've managed to horribly hack up Drupal.aloha.attach to pass the setting to the plugin, but was considering the proper way to implement this for the long term. The straitforward solution would be a new event fired before attaching Aloha, but supplied with the editor and format settings. However, Aloha already contains a way to select plugin configuration depending on selectors ( http://aloha-editor.org/guides/plugins.html ), which might be usable by setting a class for the currently selected text format on the Aloha element. This approach may simplify things together with having format settings defined globally, as a given aloha plugin only needs to specify that it wants 'this' setting for '.my-text-format', and let Aloha figure out the when and where.

But I might have missed discussions, so what does the maintainers think?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Assigned: Unassigned » Wim Leers

Did you look at how the included Caption module deals with this?

Xen’s picture

Yes, it doesn't configure the plugin per text format. Global configuration is pretty easy to deal with. What I'm after is being able to configure plugins depending on the text format.

Wim Leers’s picture

The configuration does happen on a per-text format basis, but in a different way: plug-ins are indeed global, but they're only available based on the allowed tags. I.e. without the img tag being allowed, there will be no image caption stuff. Without the b tag being allowed, there is no bold button. Etc.

Xen’s picture

Yes, but in this case there is no tag to bind to. These plugins handle custom tags (much like how the Media module inserts media), and hides the custom tag and replace them with HTML for rendering in the editor. In this case, the plugin needs to get the tag that the filter is configured to use for subheadlines, in order to display the placeholder in Aloha with the same tag (so I'll render the same way as it will end up looking when the filter later does the same thing).

Other plugin might have other configuration they want from the filter. For instance, a Media module plugin might be configured on one text format (available to most users) to only allow inserting images from OEmbed, while another text format (for editors) configures it to allow uploading of images.

As Aloha has already implemented all the complex trickery involved in getting settings from the filter to the editor depending on text format, it seems a shame not to let plugins in on the deal so the end experience of the user simply is that they configure the plugins on a text format basis (which would seem logic to them).

Wim Leers’s picture

Your reasoning is of course valid. We are trying to keep it as simple as possible though.

But you're absolutely right that WYSIWYG plug-ins should be able to be text format-specific. In your opinion, would it be acceptable to simply have an event fired whenever the text format is changed?

Xen’s picture

Assigned: Wim Leers » Xen

Well, an event would be simple to implement in the current Aloha, but I don't think it's easy from a plugin developers viewpoint.

I still think the easiest for both parties would be piggy-backing on Aloha's selection of configuration, using a class.

I'll attempt to cook up a patch to see if it is a workable idea.

Wim Leers’s picture

I'm not sure what you mean? Can you link to the specific AE functionality you're referring to?

Wim Leers’s picture

Also: THANKS for stepping up and helping with this! :) Your input is very, very deeply appreciated!

Xen’s picture

Here: http://aloha-editor.org/guides/plugins.html

I figure that if the code that fixes the data-allowed-tags when changing text format, also set a class on the element depending on the format, the plugin could provide a configuration with the 'editables' setting the correct configuration per class. If you look at that first example on that page, and mentally replace #title and #teaser with .plain-format and .simple-format (these being the classification of the text format machine name), you'll get the idea.

Then we'll only need a hook in the aloha_pre_render_text_format to allow the plugin module to discover that it should provide the proper configuration for the text formats being used. Really, it could be done without this, but then it would be up to the plugin module to add the proper settings to the configuration all on its own.

Xen’s picture

Assigned: Xen » Unassigned
Status: Active » Needs review
FileSize
7.71 KB

I discovered that it is somewhat complicated by what I'd call a Aloha bug. Currently the standard plugins use the editable.obj to figure out what config to use, but that's the div that Aloha creates for textareas, instead of the original textarea that has the classes.

We can work around this for the moment being by using getEditableConfig(editable.originalObj) instead of getEditableConfig(editable.obj) in the plugins, but we loose the option of configuring standard plugin this way. However, it's really a but that should be fixed in Aloha.

With the attached patch, a module might pass its filter configuration to the plugin like so:

function mymodule_aloha_filter_settings($format_id, $selector) {
  $list = filter_list_format($format_id);
  // See if the format uses our filter.
  if (isset($list['mymodule']) && $list['mymodule']->status) {
    if (isset($list['mymodule']->settings['config_setting'])) {
      return array(
        'plugins' => array(
          'myplugin' => array(
            'config' => array('setting' => 'default'),
            'editables' => array(
              $selector => array('setting' => $list['mymodule']->settings['config_setting']),
            ),
          ),
        ),
      );
    }
  }
}

Input?

Wim Leers’s picture

#9: Oh, yes, definitely! They recently introduced that based on our feedback — that's why we're not using it yet — we couldn't yet! :)

#10: can be worked around by creating our own div for a textarea and then binding AE to that instead. See #1791758-3: Manage our own textarea -> div mapping (fixes Aloha on textarea having style="width: x; height: y;" set).

This is also crucial for e.g. the ability to have images in format A *and* B, but only allow image captions in format A.

Will fix today.

Wim Leers’s picture

Didn't get to it yesterday, didn't get to it today :( Unexpected problems with upgrading to Aloha 0.22.1 made doing that take longer than expected: #1803040-2: Update Aloha build to Aloha 0.22.1.

If you can work on this faster than me, please be my guest :)

Wim Leers’s picture

Status: Needs review » Needs work
Xen’s picture

Assigned: Unassigned » Xen
Xen’s picture

Xen’s picture

Assigned: Xen » Unassigned
Status: Needs work » Needs review
Wim Leers’s picture

Category: support » task
Priority: Normal » Critical
Status: Needs review » Fixed
FileSize
16.8 KB

I like your work a lot — thanks! :)

With the exception of hook_aloha_filter_settings(). 1) I'm explicitly avoiding adding new hooks. 2) You're only using it for Drupal.settings.aloha.settings == Aloha.settings, which are the global settings for Aloha Editor. For global settings, please do something like in Caption.module if it does not depend on any of the "page context". If you do need to depend on the "page context", in this case on the available text formats, then please do something like this:

  $form['some textarea with processed text']['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => array('aloha' => array('settings' => array('plugins' => array(
      'pluginName' => array(
        'foo' => 'bar'
      ),
    )))),
  );

$settings can then contain editable-specific settings, as explained over at http://aloha-editor.org/guides/plugins.html#configure-plugins.

If you need it to be dependent on the text format, do something like this:

  $form['some textarea with processed text']['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => array('aloha' => array('settings' => array('plugins' => array(
      'pluginName' => array(
        'editables' => array(
          '.text-format-filtered-html' => array(
            'status' => TRUE,
          ),
          '.text-format-full-html' => array(
            'status' => FALSE,
          ),
        ),
      ),
    )))),
  );

I've updated the way the "drupal" plug-in works, it no longer relies on the data-allowed-tags attribute, instead it relies on the text format class that's being set, for which the corresponding allowed tags are then looked up (they're stored in Aloha.settings.plugins.drupal['text-format-<text format name>'].allowedTags.

Finally, currently the amount of code in AE to make it work this way is currently somewhat ridiculous. E.g. to be able to configure it like you describe, you have to do something like this. I'm sure this will become better once it's abstracted away for other plug-ins to leverage easily though :)
It'd be great if you could open an issue on AE's GitHub to request this. Then it's no longer just me making feature requests; they can see somebody else of the Drupal community wants to write AE plug-ins :)

Committed & attributed you:
- D7: http://drupalcode.org/project/aloha.git/commit/41b44f2
- D8: http://drupalcode.org/project/aloha.git/commit/90dca28

(I spent more than half my day on this. Hope you like the direction.)

Wim Leers’s picture

This breaks compatibility with Edit module by the way. Issue: #1807332: Make Edit compatible with Aloha's new method of communicating the allowed tags.

Xen’s picture

I know it's the global settings, as there's really no concept of local settings in Aloha. In particular, the 'local' settings for a particular editor is in the global Aloha.settings.plugins.myplugin.config.editables.. I decided to let hook_aloha_filter_settings return a "full" Aloha settings array to merge in, in order to allow it to add in global configuration if it was needed, but it could also be modified to assume that what the hook_aloha_filter_settings returns should go under Aloha.settings.plugins (can't go any deeper, as aloha.module can't assume anything about what plugins a module implements.

Doing it like the caption module does it, is not an option, as the point was to be able to configure it per text format.

The two examples you give looks simple, but are problematic to implement. Where is "$form['some textarea with processed text']" supposed to be? It can't be an form_alter function, as this would require the plugin module to know all forms which might contain (differently named) textareas using Aloha.

One way to get all the textareas is using a pre_render function on the form element, just as aloha.module does to add it's settings, but take a look at the logic of that function (which has been split in two by your latest commit). We'll have to duplicate most of it for each plugin, which was what I was trying to avoid by letting it call a hook to make things simple for the plugin developer. I have tried implementing a plugin this way, and it sucked so hard that I created this patch in the first place.

I don't understand the resistance towards adding a hook to make it easy for plugin developers to add their text format settings without having to add a lot of boilerplate code. The specific implementation might need some work. An alternative way, which I just thought of, don't know if work, and don't know if you'll dislike as much as a hook, is to use a new "aloha_plugin_settings" key to the array returned from hook_filter_info, and let aloha.module call that to get the plugin configuration. Not a new hook, but a callback.

I know Aloha jumps through quite a few hoops in order to support configuration per editable, but I'm not sure about what you want me to create an issue for? What I don't get is, why do it all the way down under Aloha.settings.plugins.myplugin.config.editables, instead of having the whole tree under Aloha.settings being editor specific. Makes more sense to me. Paired with a form of inheritance of a default configuration, where each editable can then have specific config items overridden would make things easier, in my opinion.

Wim Leers’s picture

Status: Fixed » Needs work

The two examples you give looks simple, but are problematic to implement. Where is "$form['some textarea with processed text']" supposed to be? It can't be an form_alter function, as this would require the plugin module to know all forms which might contain (differently named) textareas using Aloha.

You don't *need* to use #attached (and you're right, #attached is only meaningful for "local" settings, not "global/page scope" settings). You can also just use drupal_add_js(), then you don't need to use a specific render (sub)array. The text format-dependent plug-in settings are *always* present when using Aloha Editor now, hence using drupal_add_js() is fine too. That would look like this and I think that is *not* too hard:

drupal_add_js(
  array('aloha' => array('settings' => array('plugins' => array(
    'pluginName' => array(
      'editables' => array(
        '.text-format-filtered-html' => array(
          'status' => TRUE,
        ),
        '.text-format-full-html' => array(
          'status' => FALSE,
        ),
      ),
    ),
  )))),
  'setting'
);

I think what you're getting at, is that the remaining problem is: when/where to inject your text format-dependent settings: i.e. where to actually do the above. You're absolutely right there. It's painfully hard. But *why* is it painfully hard? Look at any module that provides a filter for the filter system. Almost all of them that add CSS files, do so in a hook_init() implementation, with $every_page = TRUE. Because the filter system doesn't provide any way to know whether a filter's output is present on any given page (partially due to caching), they have no other way of knowing this. Examples aplenty: caption_filter, geshifilter, spamspan, extlink, etc.

What we're seeing here is essentially the same problem. Would you agree?

I see three ways for solving this:

  1. What you said:

    An alternative way, which I just thought of, don't know if work, and don't know if you'll dislike as much as a hook, is to use a new "aloha_plugin_settings" key to the array returned from hook_filter_info, and let aloha.module call that to get the plugin configuration. Not a new hook, but a callback.

  2. Allowing libraries in hook_library() to use more than just 'css', 'js' and 'dependencies', also allow callbacks to be used, much like you can with #attached. Compare hook_library() with drupal_process_attached(). Any module wanting to insert text format-specific settings could just add a callback by using hook_library_alter(). That callback would then call drupal_add_js() as in the above example.
  3. Specifically allowing hook_library() to return dynamic results (i.e. the results are not cached, they're rebuilt for every page load). This is currently disallowed by the docs, but possible in practice. Then we could do the following: implement hook_library_alter(&$libraries, $module), check if $module == 'aloha' and then call drupal_add_js() as in the above example.

Setting back to NW because this problem isn't fully solved yet.


I don't understand the resistance towards adding a hook to make it easy for plugin developers to add their text format settings without having to add a lot of boilerplate code.

I'm trying to make sure that Drupal 8 won't ship with Aloha-specific hooks. We want to make the barrier as low as possible for alternative WYSIWYG implementations.

I know Aloha jumps through quite a few hoops in order to support configuration per editable, but I'm not sure about what you want me to create an issue for?

To make it easier (trivial!) for plug-ins to support editable-specific settings.

What I don't get is, why do it all the way down under Aloha.settings.plugins.myplugin.config.editables, instead of having the whole tree under Aloha.settings being editor specific.

You could propose that too, but in any case this is not something that is up to me/us to decide. It's how Aloha Editor works.
In case you're trying to say "why don't we provide text format- or editable-specific Aloha.settings?", then the answer is simple: Aloha Editor can only be instantiated once per page. There is only a single, global instance. A singleton. Hence it must be reconfigured on a per-editable basis.

Xen’s picture

OK, I agree that using drupal_add_js is just as good, but as you say, determining when to inject text format dependent settings is the tricky part.

However, we do have the advantage over modules adding CSS in hook_init(), as we can know what filters are available on a given page, due to the pre_render function in aloha.module. We only care about when what filter is being used in an editing context (CSS for the end result will still have to be done the $every_page way), and so aloha can just add the settings for the used filters.

I'm trying to make sure that Drupal 8 won't ship with Aloha-specific hooks. We want to make the barrier as low as possible for alternative WYSIWYG implementations.

Well, we have a conflict of interest here. We (the project I'm working on) chose Aloha for the possibilities for custom extension, not for it's swapability. In theory I agree that it's a noble goal to make the RTE as swappable as possible, the problem is that you end up with the lowest common denominator. The WYSIWYG module has been going down this path for some time, and how many addons for it is there?

Playing the devils advocate, this whole issue goes against that goal, if we see it as something alternative RTEs should be able to duplicate. CKEditor can never use a plugin written for Aloha. No matter what the solution, there's a hook, explicit or implicit, that's Aloha specific.

That said, however, I prefer solution 1. Apart from having the excellent quality of being my own idea, it's simple to understand, explain, and implement. And it makes sense to have it in the filter_info. If we get a competing RTE editor, it can use a similar mechanism, and allow modules to support both, if they have the resources.

I'm not even sure I understand option 2 and 3, and I consider myself a pretty capable Drupal developer. I think there's a bit too much fiddling with magic arrays involved with working with aloha.module, for my liking already, and I can't imagine how a relative newbie might feel.

There is only a single, global instance. A singleton. Hence it must be reconfigured on a per-editable basis.

If we could dynamically swap the settings for that instance, it wouldn't be such a problem, but that's not possible with the current architecture. But it is somewhat a problem that Aloha works under the assumption that every editable on the page is equal, with the "plugin configuration per editable" feature haphazardly thrown in for good measure. But it's complicated to change, even if getting blessed by the upstream maintainers.

To make it easier (trivial!) for plug-ins to support editable-specific settings.

Oh, right. Well, I was a bit confused by the things you linked to. the last one is definitely wrong, it should use Aloha.activeEditable.is() on the keys of something, in order to duplicate the logic of the plugin implementation... But as you say, it complicates things. Perhaps a more solid solution would be to implement a config class (I'm surprised they haven't already), and let it handle the logic of finding the right settings. But I haven't looked into all of Alohas config usage, so I don't know if that's feasible.

Wim Leers’s picture

However, we do have the advantage over modules adding CSS in hook_init(), as we can know what filters are available on a given page, due to the pre_render function in aloha.module.

No! We only know that for *forms* that use the format selector! We do *not* know that on the front-end (though currently — and most likely this will remain the case — the only implementation for that is the Edit module). We do *not* know that on forms that don't use the format selector (though, granted, they are a minority).

Well, we have a conflict of interest here. We (the project I'm working on) chose Aloha for the possibilities for custom extension, not for it's swapability. In theory I agree that it's a noble goal to make the RTE as swappable as possible, the problem is that you end up with the lowest common denominator. The WYSIWYG module has been going down this path for some time, and how many addons for it is there?

I agree. But the only way we're going to get this in Drupal 8 core, is if it's going to be swappable.

That said, however, I prefer solution 1. Apart from having the excellent quality of being my own idea, it's simple to understand, explain, and implement. And it makes sense to have it in the filter_info. If we get a competing RTE editor, it can use a similar mechanism, and allow modules to support both, if they have the resources.

Oh noes! I was going to say that this makes most conceptual sense to me too. But then I realized this is hook_FILTER_info(). It's about filters. We don't need to be able to configure editables based on filters, but on text formats. Hence this actually doesn't work…

Which only leaves three options:
1. An Aloha-specific hook.
2. #20, option 2
3. #20, option 3

If we could dynamically swap the settings for that instance, it wouldn't be such a problem, but that's not possible with the current architecture.

Indeed.

Oh, right. Well, I was a bit confused by the things you linked to.

Fair enough — this area of AE is way too confusing. Which is why we need to file an issue about it :)

Xen’s picture

We only know that for *forms* that use the format selector!

Yes, but that's pretty much what we can support out of the box.

From what I can gather from a quick lookie, edit.module looks at the fields and extracts the filter id, so it knows the filter of the fields.

Also it seems to gather the data-allowed-tags attribute, which duplicates code in aloha.module. Shouldn't it rather call a hook in the selected wysiwyg module, to allow the given module to do whatever magic it needs?

Modules that uses formats in odd ways not through the format selector? Well, there's nothing much we can do about that.

I agree. But the only way we're going to get this in Drupal 8 core, is if it's going to be swappable.

So basically, we can't implement this, because if it's in core, it needs to be swappable, and custom Aloha plugins is never going to be swappable? Do we have to create a adv_aloha module for this kind of thing then?

Hmm, talking a step back, WYSIWYG plugins is always going to be bound to a particular editor, and if Aloha gets in core, it'll get an advantage over other editors, as people is more likely to make plugins for it due to it being the de-facto standard editor. And that's going to happen whether we provide an API for integration or not, if we don't, people will just hack around the lack of API (look at how Page Manager overrides standard Drupal menu callbacks for an example), in order to make Cool Stuff (TM). Really, the only way to ensure swapability is to *not* include any editor at all but only an API.

One might argue that an API where it's well documented what's general
WYSIWYG API, and what's specific to a particular editor is more likely to foster interoperability.

Oh noes! I was going to say that this makes most conceptual sense to me too. But then I realized this is hook_FILTER_info(). It's about filters. We don't need to be able to configure editables based on filters, but on text formats. Hence this actually doesn't work…

But a text format is a collection of filters. Without any filters, it's nothing (well, a pass-through security hole in any case). Filters are the things that makes text formats work.

But yes, it assumes that any plugin that needs configuration will have a companion filter that does something. A hook doesn't have this limitation.

Which only leaves three options:

As I see it, it still hard to implement per text format settings in 2 and 3. At that point in the request, there's no way to know what formats is being used on the page, so the only option is to loop through all formats defined in the site (but that might be the safer bet), whether aloha is active for the given format (which is not possible in the current version), check if it applies to a given format (in the case that it has a companion filter), and add settings for all, as the current aloha_add_format_settings() does. Which is doable, but currently it requires all plugin modules to duplicate the looping logic of said function, which seems a waste to me.

In any case, seems to me that 2 and 3 requires patching core, which is problematic with D7?

Currently, the only workable solution I can see is a hook. A hook_aloha_add_format_settings_alter might be all that's needed. But I could still be missing something.

Gods, getting Alohas plugin configuration code fixed up might turn out to be the easy part. :-)

Wim Leers’s picture

Hmm, talking a step back, WYSIWYG plugins is always going to be bound to a particular editor, and if Aloha gets in core, it'll get an advantage over other editors, as people is more likely to make plugins for it due to it being the de-facto standard editor. And that's going to happen whether we provide an API for integration or not, if we don't, people will just hack around the lack of API

Agreed. The reason I'm trying very hard to not have a new hook, is to make it easier to get the core patch accepted. However, I'm now okay with including a hook for this. It'll make the code for developers needing to configure plug-ins on a per-textformat basis a lot simpler.

But a text format is a collection of filters. Without any filters, it's nothing (well, a pass-through security hole in any case). Filters are the things that makes text formats work.

But yes, it assumes that any plugin that needs configuration will have a companion filter that does something. A hook doesn't have this limitation.

The current Aloha module has the following "levels" of configuration: 1) global, 2) text-format.

You're saying that it should really have the following "levels" of configuration: 1) global, 2) text-format, 3) filter. Because in many cases, filters will be "the things" that come with Aloha Editor plug-ins to provide similar functionality while editing in the WYSIWYG editor.

The problem here though is that "a filter" is not always meaningful. For example, "the" filter_html filter is meaningless. It only becomes meaningful once you know how it is configured within a specific text format, i.e. what its allowed tags are.
For that reason, I think the hook should be hook_aloha_format_settings($format). Modules providing filter implementations + accompanying AE plug-ins can *still* implement this, check if the relevant filters are present, and then send format-specific settings. Modules that are providing a filter-agnostic AE plug-in can *also* leverage it.
I think it's the best of both worlds, no?

Gods, getting Alohas plugin configuration code fixed up might turn out to be the easy part. :-)

I doubt that :P

Xen’s picture

You're saying that it should really have the following "levels" of configuration: 1) global, 2) text-format, 3) filter.

Well, what I really meant was closer to what you're describing. I agree that a filter on its own doesn't make sense, I was thinking more along the lines of "this filter, in this text format".

hook_aloha_format_settings($format)

I like that. Plugin doesn't have to loop through the formats themselves, but can let aloha.module figure out which formats we'll want config for (whether aloha then loops through them all, is alohas business). Having to check for your own filter is fine as you say, it allows for non-filter specific plugins to use it too.

I think it's the best of both worlds, no?

Indeed. :-)

Just to check the details:

I'd say that hook_aloha_format_settings() should provide the class name used for the format ether as an argument, or in the $format object, so the plugin module doesn't have to guess it.

Implementing hook_aloha_format_settings() could look like this (passing the class as $format->selector):

function mymodule_aloha_format_settings($format) {
  $list = filter_list_format($format->format);
  // See if the format uses our filter.
  if (isset($list['myfilter']) && $list['myfilter']->status) {
    if (isset($list['myfilter']->settings['somesetting'])) {
      $settings =  array(
        'plugins' => array(
          'myplugin' => array(
            'config' => array(),
            'editables' => array(
              $format->selector => array(, $list['myfilter']->settings['somesetting']),
            ),
          ),
        ),
      );
      drupal_add_js(array('aloha' => array('settings' => $settings)), 'setting');
    }
  }
}

Yes?

It is tempting to create a helper function so it becomes:

drupal_add_js(aloha_plugin_settings('myplugin', $conf), 'setting');

Wim Leers’s picture

To make it easier (trivial!) for plug-ins to support editable-specific settings.

Oh, right. Well, I was a bit confused by the things you linked to. the last one is definitely wrong, it should use Aloha.activeEditable.is() on the keys of something, in order to duplicate the logic of the plugin implementation... But as you say, it complicates things. Perhaps a more solid solution would be to implement a config class (I'm surprised they haven't already), and let it handle the logic of finding the right settings. But I haven't looked into all of Alohas config usage, so I don't know if that's feasible.

I didn't actually know that they had plugin.js/getEditableConfig(). This comment on GitHub made me find it. And only now I noticed you already knew this. So, it looks like the Aloha side of this problem has already been addressed :)
I'm not sure why you think this is inadequate though? It sure could be better, but this is workable, no?

I like that. Plugin doesn't have to loop through the formats themselves, but can let aloha.module figure out which formats we'll want config for (whether aloha then loops through them all, is alohas business). Having to check for your own filter is fine as you say, it allows for non-filter specific plugins to use it too.

Exactly! :) Glad we're on the same page :)

I'd say that hook_aloha_format_settings() should provide the class name used for the format ether as an argument, or in the $format object, so the plugin module doesn't have to guess it.

Of course. I'd say: hook_aloha_format_settings($format, $selector). I wouldn't overload $format with more information, because people might assume $format as loaded through filter_format_load() will also contain it, but that won't be the case.

It is tempting to create a helper function so it becomes:

drupal_add_js(aloha_plugin_settings('myplugin', $conf), 'setting');

Tempting indeed. I had something near-identical, but removed it just two days ago: #1807326: Get rid of aloha_plugin_js_settings(). So I'd rather not do that :)

Xen’s picture

Assigned: Unassigned » Xen

It sure could be better, but this is workable, no?

It's a bit wonky, but it works yes. There's some issues around the contentHandler.sanitize thing you pointed out, but it's serviceable for now.

Exactly! :) Glad we're on the same page :)

Excellent. :-)

Of course. I'd say: hook_aloha_format_settings($format, $selector).

Fine by me, makes total sense.

I'd rather not do that :)

I get the motivation behind removing it, but on the other hand I think it's pretty ugly to have these big nested arrays where half the keys are boilerplate. Goes with Drupal.settings, I guess...

I can whip up a patch tomorrow, I already have code that wants to use the feature.

Xen’s picture

Assigned: Xen » Unassigned
Status: Needs work » Needs review
FileSize
932 bytes

And here. Pretty close so what I had in the original patch.

I've taken the liberty of changing the $selector argument to $class. Means that the hook has to add the leading dot itself, but then it doesn't have to do string manipulation to get the simple class name (in case it wants to invoke other kinds of JS magic).

After a bit of rewriting, my module that uses the feature works fine.

Wim Leers’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
Wim Leers’s picture

Darn, I had not seen this patch :( Will review ASAP!

Wim Leers’s picture

Status: Needs review » Needs work

Maybe it would be better to pass in a $settings array by reference that other modules can add things to? Then those modules don't need to call drupal_add_js() anymore.

Thoughts?

Other than that, I'm in favor.

Xen’s picture

That's pretty close to my original version, apart from it letting the plugin return the settings rather than altering them. ;-)

But, yeah, having each plugin do a drupal_add_js seems to be a bit roundabout when in 99% of the cases the plugin wants to add settings to the aloha settings array.

Wim Leers’s picture

Status: Needs work » Reviewed & tested by the community

Sorry for the silence. I've been working 150% of my time on Edit.

Xen’s picture

I can add in the $settings by reference thing, if want?

Wim Leers’s picture

Status: Reviewed & tested by the community » Postponed

Eh…, #33 was a bit too fast, yes. $settings should be there, but more importantly, you're calling the format object $filter. That's confusing to say the least.

Furthermore, this may now actually have to change once #1833716: WYSIWYG: Introduce "Text editors" as part of filter format configuration lands (Aloha patch: #1833720: Leverage new Drupal 8 text editor bindings). Let's postpone this for now, to not make an even bigger mess out of this.