Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Thoughts on getting the HTML code of a custom block under the control of an IDE?

I'm talking about the regular "Add block" feature where you're normally supposed to write the HTML in the block-configuration text field. This IDE integration would be for the sake of letting front-end developers use their preferred HTML editor as well as letting them commit iterations of that code into version control.

I'm aware of "exporting configuration to code", but I'm interested in finding a workflow where the developers don't have to perform the export every single time they have code to commit.

share|improve this question

2 Answers

It's a complicated matter, because Drupal isn't keen on adding self-made HTML in his projects. But, however, you can force Drupal to use your HTML code by using the hook_block_info() and the hook_block_view() function. In this way, you will add a block in your code (you can easily access the code by using Eclipse, Aptana,... or any other editor your developers like).

Here is an example:

function yourmodule_block_info() {
    $blocks['blockname']['info'] = 'Some info about the block';
    $blocks['blockname']['cache'] = DRUPAL_CACHE_PER_USER;
    return $blocks
}

function yourmodule_block_view($delta) {
    if ('blockname' == $delta) {
        $block['subject'] = 'The subject of the block';
        $block['content'] = 'This is the content of the block';
        return $block;
    }
}

In this way, you can add just about anything you like in the $block['content'] part.

I hope this helps you out a bit. If not, please let me know!

share|improve this answer
Hm, well I should have specified that I don't want the people who I'm calling "front-end developers" writing modules just to create static blocks. Naturally a custom module's code can be both editor-edited (rather than textfield) and versioncontrolled (as distinct files). – Beanluc Jan 20 '12 at 16:54
How about looking at it from this perspective: Let's say I have persons who use the Full HTML input format on nodes (forget blocks, and let's also not consider page callback). Let's say those persons to be able to use their editor programs to write/edit this HTML rather than being stuck with the browser's textfield as the only place where editing such HTML code is possible... Any thoughts? This is the problem I'm trying to solve, at least with regard to editing. – Beanluc Jan 20 '12 at 17:05
I still want versioncontrol too. At least on a node, there's a revisions module, but, I'm also thinking that an IDE could put it in the real code repository if it was also being used for editing. – Beanluc Jan 20 '12 at 17:06

Probably the simplest way to do blocks this way is via the Nodeblock module. As the developers describe it

This module allows you to specify content type(s) as being a block. This allows the content managers of the site to edit the block text and title without having to access the block administration page. Users only need edit access to that node in order to edit it.

Not only does this make it possible for users to edit blocks without having admin permissions, it also lets you do versioning and use the normal html workflow you would use for any node.

share|improve this answer
This doesn't address either of my actual needs, those being: integration with the developer's code-editing program of choice, and, capturing versions of the code with git. – Beanluc Jan 20 '12 at 17:35
I guess, then, that I don't understand your requirement. Your question seems to be saying you want to edit the content of a block in the same way as you do other html content - which, in Drupal, mostly means the same way you deal with nodes. – jmarkel Jan 20 '12 at 23:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.