I find adding an encoded node->title to the html classes is needed for CSS designers. Using the node->nid is not good and can have issues if you use node export/import that can change node ordering.

Adding this small piece of code I now render content as blocks with good class CSS like I had using my old workaround with views.

The views module renders the view's->title with block as the prefix and postfix.
I used the same name style so I have the added benefit of reusing the same CSS that was previously used while using the views hack to display content nodes as blocks.

Here is my somewhat sloppy fix in: node-nodeblock-default.tpl.php

...
if( $node->title ) {
  $classes .= ' block-' . strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $node->title)) . '-block';
}
?>
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
...

It does the trick.. But I'm sure you know a better solution.

Please patch soon :)
Thanks.

Comments

steverweber’s picture

I don't care much for the -block postfix. kinda looks sloppy to me.. drop it if you want.

Johnny vd Laar’s picture

Status: Active » Closed (won't fix)

Node titles are even more subject to change. I think you should use a module like block class to accomplish this. http://drupal.org/project/block_class

In the near future I'm planning a machine name field on the node block node.

steverweber’s picture

I have created a machine name field patch.
So now the settings can be saved in features without issues of id offsets.

The patch is not backwards compatible... However I feel its a good direction.
I'll post it sometime tomorrow after some extra testing.

Thanks..

steverweber’s picture

I attached the patch... Note I still have some debug output chilling in there...
It needs some work however for the most part it works.

The issues...
- I'm not sure how to handle nodeblock_translation_fallback_
- using the node title as the machine name could clead to overlap... might be nice to make this value a field for user to custom

Johnny vd Laar’s picture

Thanks for the patch. I'm currently not able to look at it but I'll look into it whenever I have time.

Johnny vd Laar’s picture

I have added a machine name field.

It's added here:
http://drupalcode.org/project/nodeblock.git/commitdiff/23ab1cb?hp=9fd890...

Please reopen this one if you find a bug in this.

steverweber’s picture

steverweber’s picture

Status: Needs work » Closed (won't fix)
steverweber’s picture

Status: Closed (won't fix) » Needs work

I'm exporting my nodes with block info using features.fe_block_settings...

When importing settings for content and blocks I hit this Notice.

Notice: Undefined index: custom_machine_name in nodeblock_node_insert() (line ~291 of nodeblock/nodeblock.module).
line:

if (!$values['custom_machine_name']) {

my $values are:

    [nodeblock] => Array
        (
            [nid] => 1
            [enabled] => 1
            [machine_name] => static_css_js
            [view_mode] => node_block_default
            [node_link] => node_block_default
            [comment_link] => node_block_default
            [translation_fallback] => 0
        )

I use something like this to work around that issue.?

if (!isset($values['custom_machine_name']) && !isset($values['machine_name']) ) {

Another issue:
When creating new nodes that don't have nodeblock... I get this notice and error:

Notice: Undefined property: stdClass::$nodeblock in nodeblock_node_insert() (line 290 of /home/s8weber/srv/drupal2/srv/drupal/profiles/uwlib_profile/modules/custom/nodeblock/nodeblock.module).
PDOException: SQLSTATE[HY000]: General error: 1364 Field 'view_mode' doesn't have a default value: INSERT INTO {nodeblock} (machine_name, nid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => 2 ) in nodeblock_node_insert() (line 299 of /home/s8weber/srv/drupal2/srv/drupal/profiles/uwlib_profile/modules/custom/nodeblock/nodeblock.module)

my workaround is to ignore nodes that dont pass nodeblock_type_enabled

function nodeblock_node_insert($node) {
  if(!nodeblock_type_enabled($node->type)) {
     return;
  }

I then hit more issues when creating new nodes with that have nodeblock enabled but node->nodeblock is not set...

function nodeblock_node_insert($node) {
  if(!nodeblock_type_enabled($node->type)) {
     return;
  }

  if ($node->status && user_access('administer blocks')) {
    drupal_set_message(t('The block you just created is now available on the <a href="@url">block configuration page</a>.', array('@url' => url('admin/structure/block'))));
  }
  
  $values = array();
  if (isset($node->nodeblock) ){
    $values = $node->nodeblock;
  } else {
    $values['enabled'] = 1;
    $values['view_mode'] = 'node_block_default';
    $values['node_link'] = 'node_block_default';
    $values['comment_link'] = 'node_block_default';
    $values['translation_fallback'] = '0';
  }
  if (!isset($values['custom_machine_name']) && !isset($values['machine_name']) ) {
    $values['machine_name'] = $node->nid;
  }
  unset($values['custom_machine_name']);
  $values['nid'] = $node->nid;

  db_insert('nodeblock')
    ->fields($values)
    ->execute();

  _nodeblock_rehash_all();
}

Some of the issues might be caused my my profile... Perhaps my testing was a little helpful.
Thanks.

Johnny vd Laar’s picture

Status: Closed (won't fix) » Fixed

I've added a fix with this commit:
http://drupalcode.org/project/nodeblock.git/commit/43d6985

Let me hear if the problem persists please.

steverweber’s picture

Excellent turnaround.
I'll give it another round of testing.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.