I wrote a little module based on this one, that saves all in files located in the theme directory, and when i say files is images too.

Why i did that? Well, i prefer code being in code, and templates should be in themes, not as content, this generates problems when we have to separate functionality x content. For example, the image that illustrates the template is storage in the files directory, so now if a roll a deploy, the image it will disappear, and if we upload a new image, the feature is going to look like something is override, and this can be a pain in the ass when you have continuous integration and the features are always reverted to default.

This make sense for someone? If it is, i have a suggestion.

Some modules(like views, context...) have the UI as an optional module, not obligatory thing. Can we just offer the two things? making some APIs :D

Lets say we have a module with one submodule(this is a suggestion):

  1. wysiwyg_template
  2. wysiwyg_template_ui, or wysiwyg_template_crud, or wysiwyg_template_entity

We can then make this to work with the Theme API, this can benefits from at least two thing:

  1. Independent from wysiyg editor library(ckeditor, TinyMCE...)
  2. Avoid html templates in javascript files, like templates.js (yuck!)
  3. Templates in the theme directory, not in a module, different theme, different templates(maybe)

So, what i mean is: More code and less content.

I will really like to hear some thoughts about this two suggestions :)

  1. Separate Entity CRUD, into a sub module, creating a module with the API.
  2. Use the Theme API, something like wysiwyg-template--[machine-name].tpl.php

Cheers!,
Sebas.

Comments

guybedford’s picture

I would think that separating out this module into two would be a bit of a waste. Separating the interface from the implementation only makes users download two modules when they could just download one.

I would rather suggest:

* Have all editor supports in this module, with some special checking to see which wysiwyg module is installed.
* Convert this module to a file-based template system

If you are keen to work in these directions, I am happy to review and handover the reigns in due course here.

sebas5384’s picture

Hey! thanxs for your thoughts!

But, I was talking more like in a sub-modules thing, like the examples I said above: views, views_ui or context, context_ui, where the module views for example only contains the api and functionalities of Views, then the other one views_ui haves all the UI interface.
This is a good example of the use of a modular system.

I'm willing to spent a really good time doing a 3.x version, with help, of course :)

Cheers!,
Sebas.

jenlampton’s picture

I do really like the idea of having a file-based template system for this module. You're right, templates should be stored in code.

In general, I'm against having templates for content stored in a theme. If the templates are in the theme then when the theme is changed, the content will break. For me, if the templates are for content, they need to be stored with the content (in the files directory, maybe?). I don't see any harm in letting you put your own templates wherever you like, so perhaps also a UI that would allow you to define an alternate location of the template files.

I'm also against the idea of having a sub-module just for the user interface. The reason views (and context too, probably) has a separate module for the UI is because there is a LOT of code that drives the Views UI, and a lot of it is on the front-end (javascript) and makes your pages heavy. For this module, there's not a lot of extra code, it's just a plugin for your existing WYSIWYG editor, and there's no need for a whole separate sub-module to manage a user interface.

sebas5384’s picture

Thanks jenlampton!

I think you are right about the sub-modules topic, and like guybedford said "would be a bit of a waste", I just wanna have the choice of disable (or not have at all) the interface, wich generate templates files in the DB, but it's ok, lets move on to the other ones.

Wysiwyg Template API and templates in files:

Why?

Today I work with a team of devs, and when is created a template it will require re creation of a Feature to pass the new exported template to everyone else, and this is pretty nice. But! now what about the thumb image? even sending the image to upload my devs colleges will generate problems like Features override for ever, and with every feature revert I will be loosing again the reference to the fid created in my local DB, eventually the editor user will suffer with this problem in every deploy.
The front-end engineers will suffer with the fact of having to code the template in a textarea, so every update or even through the development process will have to copy the code, paste it in a editor of preference, bla bla... borring! so code must be in code.

What can we do about this issues?

We can create a hook based API to declare our templates files, what files? templates files(.tpl.php) you already know how to deal with, suggestions like wysiwyg-templates--[machine-name].tpl.php
Important!, after the editor user inserts the template of choice in the textarea(like the body field of a content type) theres no relation or reference between the templates files. So if you change the default Theme, your content will remain the same. Good news, right? yeah, but there can be a problem, if you wanna make a little change in the markup, the changes will not reflect in content already created, remember, wysiwyg templates doesn't have any relation to the content.

So here is some suggestion of a hook:

/**
 * Implements hook_wisywig_template_info().
 */
function hook_wisywig_template_info() {

  $template_path = 'wysiwyg';
  $image_path = $template_path . '/img';

  return array(
    // Table with a Footer.
    'table_with_footer' => array(
      'title' => 'Table with Footer',
      // Optional, default: NULL
      'description' => 'Table with a footer and a paragraph in it at the end.',
      // Optional, default: NULL
      'image' => 'wisiwyg-template--table-with-footer.jpg',
      // Optional, default: "wysiwyg/img"
      'image_path' => $image_path,
      // Optional, default: "wisywig-template--[machine-name]"
      'template' => 'wisywig-template--table-with-footer',
      // Optional, default: "wysiwyg"
      'path' => $template_path,
    ),
    // Table with a Header.
    'table_with_header' => array(
      'title' => 'Table with header',
      'description' => 'Table with a header and a title in it.',
      'image' => 'wisiwyg-template--table-with-header.jpg',
    ),
    // Image with a right text.
    'image_with_right_text' => array(
      'title' => 'Image with a right text',
      'description' => 'Image(size 100x150) aligned to the left with a right text.',
    ),
  );
}

This hook assumes the templates are in your current or default theme, just like the hook_theme() works, besides maybe later will registered all the wisywig templates in it, using the drupal theme system, can open some other possibilities in the feature.

I have another suggestion of a "hook", but I prefer the first one:

/**
 * Implements hook_theme().
 */
function hook_theme() {

  $template_path = 'wysiwyg';
  $image_path = $template_path . '/img';

  return array(
    // Table with a Footer.
    'table_with_footer' => array(
      // Wysiwyg template's settings.
      'wysiwyg_template' => array(
        'title' => 'Table with Footer',
        // Optional, default: NULL
        'description' => 'Table with a footer and a paragraph in it at the end.',
        // Optional, default: NULL
        'image' => 'wisiwyg-template--table-with-footer.jpg',
        // Optional, default: "wysiwyg/img"
        'image_path' => $image_path,
      ),
      // Optional, default: "wysiwyg"
      'path' => $template_path,
      // Optional, default: "wisywig-template--[machine-name]"
      'template' => 'wisywig-template--table-with-footer',
    ),
    // Table with a Header.
    'table_with_header' => array(
      'wysiwyg_template' => array(
        'title' => 'Table with header',
        'description' => 'Table with a header and a title in it.',
        'image' => 'wisiwyg-template--table-with-header.jpg',
      ),
    ),
    // Image with a right text.
    'image_with_right_text' => array(
      'wysiwyg_template' => array(
        'title' => 'Image with a right text',
        'description' => 'Image(size 100x150) aligned to the left with a right text.',
      ),
    ),
  );
}

So, if someone likes the approaches suggested above, I can start doing a patch to a possible start of 3.x-dev branch :)

Cheers!

guybedford’s picture

Thanks for your input, this is sounding great. Jen I agree with your points entirely - I don't think there's much disagreement over a file-based approach. Yes the templates don't remain a live reference, but I don't think that's too much of an issue.

In terms of the hook I really like your first suggestion - seems the most natural. Perhaps one could leave out the "template_path" and "path" properties by allowing "template" and "image" paths with a default base path assumed when none is given. Eg allow "my-template.tpl.php" or "/sites/all/themes/another/template.tpl.php". It's not a big thing though.

More than happy for you to go ahead with a 3.x branch here. Do you have git access? You're welcome to start with a patch or we can set you up as a maintainer to work on the 3.x branch if you like?

guybedford’s picture

Actually we should probably clarify something here - Ive kind of assumed here that if we move to a file-based system for wysiwyg templates, the interface should be converted to the file-based system. In other words, while the templates are saved as files for version control, one could still see and edit the list in the current interface. This isn't trivial based on your hook suggestion unfortunately. But I would strongly advise looking into this as I think it makes it harder for users to have to edit template files over FTP just to add a new template style. Any thoughts or suggestions here?

sebas5384’s picture

I wouldn't worry about that, because in the case the user creates a template through the interface, it can always use the features to export.

But, the thumb image probably must go in the feature along with the export. For that we can think in some solutions, this make sense to you?

Yeah! would be an honor to work with you guys in a dev branch of the 3.0 version, and even more as a maintainer.
I think when you give me the permissions as a maintainer i would be able to push the new branch :)

Cheers!

guybedford’s picture

I think the decision has to be made to go one way or the other. Using both methods would only confuse users. I'm happy to consider either direction - including image support in features, or migrating the system to a file-based approach. But doing both partially doesn't seem to solve either.

sebas5384’s picture

I see your point, but for me is a little weird if the interface write only in file-based, and i don't know if that is a good practice, today the Features module do that and always remain a database copy and enable the user to override it and make some changes.

Some suggestions and what we have for now:

1. Templates are always file-based, so will be necessary to write in files, where? default theme? here is some working being done for files exporting with uuid and Features http://drupal.org/node/1229670 and here http://drupal.org/node/808690

2. Two systems of templates for one functionality, through interface will write into database and then exporting using Features, or through the API wich enable the user to use a file-based templates just like theme() system of Drupal. What about the thumb image? no relation with Drupal files(fid) making image names and paths suggestions, for example the default Theme directory.

3. The user interface save the template data* into the database, still the API hook will be something like Views does with hook_views_default_views() converting the render of Features export into a file like [module].features.wysiwyg_template.inc using the hook_wisywig_template_default() based in the first suggestion of a hook(hook_wysiwyg_template_info()), with some differences like the "body" property wich contains the template's html code.
So the hook will save into the database too, and this is very well done by the Ctools export ui, this way is going to be more easy to manage the storage, in code and in the database.

The problem of the image repeats in all the cases, so I think we can came up with some idea for all the cases:
- Just in database.
- Just in code.
- In database and in code, through Features export.

Something to consider is the image upload could be optional, instead the use of "template image thumb" name suggestions. Other observation, the images are really light and small(100x70 pixels), so, we can do a simple serialize using base64 hashing, example:

iVBORw0KGgoAAAANSUhEUgAAAGQAAABGC ... ErkJggg==

this will avoid saving images into the upload directory when the template comes from the database.

The choice of templates being in files could be an option when creates/update the template through the UI, disabling the Body field, maybe this can work for the image problem too :)

Well, is a lot to think about, but something that I really liked is a move to Ctools export UI, just seems a perfect fit.

Cheers!

guybedford’s picture

Wow, a lot of options! Is it not possible to add the image into the current features support with something like those links you copied?

It does sound to me though, that keeping with the features approach could be simpler than trying to migrate away from a database mechanism at this point.

The other suggestions of moving to Ctools export (would that make image export easier?) could also be an option.

Although perhaps the data-uri approach would actually be the simplest to implement, as it only involves modifying the image upload process, and leaving some support for backwards compatibility (even if image export isn't backwards compatible).

So out of:
1. Moving to a file-base approach
2. Setting up image export in features
3. Moving to ctools export
4. Using data-uris

Which one do you think is best to go for?

snipebin’s picture

Hey guys!

@sebas5384 asked me to pitch in on the effort with you guys, so we got to discussing the possible approaches for this.

The direction we want to go is with ctools export, which will give us automatic integration with features.
As for image exportation, we will use base64 encoded strings, also exportable through the ctools plugin.

So the result is a system similar to views, which has it's own schema, and handles code/db state states through ctools, and therefore, features capable.

What do you think?

guybedford’s picture

So you would keep the templates in the db as is with the current interface?

I don't know much about the difference between ctools export and features - are there disadvantages to this approach?

All sounds great to me though - thanks for picking this up.

snipebin’s picture

To answer your first question:

Yes, as long as they are not exported to code. Once they are exported to code, Ctools export moves your database settings to code and once they are exported, Drupal doesn’t use the database entries anymore.

As for the choice between one or another:

Both APIs are great, and basically do the same thing, but we find the Ctools export ui api easier to work with and suited for our needs, please see http://www.bariswanschers.com/blog/exporting-your-module-configuration-u...

If for some reason we see that the Ctools export ui api gets in our way, we can easily switch to features api. The disadvantage there in using the features that it obligates users to use features to export. With Ctools, Features use is optional.

I appreciate your proactive stance to us contributing with this!

Could you create a 7.x-3.x-dev and include @sebas5384 and myself in project so that we can get started?

guybedford’s picture

I've added you both as maintainers to the project now.

Keep us updated here on your progress and I'll gladly test out working code you have.

Good luck!

snipebin’s picture

we'll keep you posted, thanks a lot!

caschbre’s picture

Exciting stuff! I was actually going to start looking into something like this for a current project.

I like the idea of ctools exportables and prefer the hook_wysiwyg_template_info approach.

jurgenhaas’s picture

Hey guys, I get acquainted with this module and my objective is to maintain it on an ongoing basis. While getting the issue queue sorted I stumbeled across this one and wonder if there has been any progress and if anyone wants to take this forward. It may well go into the 2.x branch. @snipebin @sebas5384 have you done any coding yet?

revagomes’s picture

I'm interested in to contribute to this.

@jurgenhaas, @sebas5384 and @snipebin

I'm not really available right now to contribute a huge amount of code but I can start with little contributions and getting more involved gradually.

You can count on me to help getting this done.

jurgenhaas’s picture

Status: Active » Postponed

Setting this to postponed status until we find the resources to work on it.

RAWDESK’s picture

Subscribing + adding related new issue mentioning an alternative solution for hosting templates in theme layer :
https://www.drupal.org/node/2811575