1

A Drupal 7 newbie here, with the following problem.

I have enabled my block with it's dependencies, but doesn't show in the block list

Can anyone spot anything I might've missed in my code?

Any help to point me in the right direction will be deeply appreciated!

Thanks in advance!

The code is the following.

.info file

name = Bloque para el buscador - INMO
description = Bloque para mostrar el buscador geográfico de InmoAnuncios.
package = Modulos de Inmo Anuncios  
core = 7.x

scripts[] = bloque_buscador.js // exist in folder

dependencies[] = inmo_node_form // enabled 

.module file

<?php

/**
 * @file 
 * Modulo para el buscador de inmuebles
 * 
 * Este modulo provee de un bloque donde se despliega un buscador de inmuebles en el sitio
 */


/**
 * Implementa el hook_block_info() 
 * Este hook le dice a DRUPAL que este bloque se puede desplegar tanto en el home page como en el sidebar
 */
function bloque_buscador_block_info() {

    $blocks = array();

    $blocks['bloque_home'] = array(
        'info' => t('Inmo Buscador (home)'),
        'cache' => DRUPAL_NO_CACHE,
    );

    $blocks['bloque_sidebar'] = array(
        'info' => t('Inmo Buscador (sidebar)'),
        'cache' => DRUPAL_NO_CACHE,
    );

    return $blocks;
}

/**
 * 
 * @param type $delta
 * @return type
 * Implementa el hook_block_view()
 * 
 * 
 */
function bloque_buscador_block_view($delta = '') {

    $estados = db_query("SELECT * FROM estados WHERE enabled = 1;");
    $inmuebles = db_query("SELECT * FROM tipo_inmueble WHERE enabled = 1;");

    $optEstados = '';

    foreach ($estados as $estado) {
        $optEstados .= "<option value=\"{$estado->id}\">{$estado->nombre}</option>\n";
    }

    $optInmuebles = '<option value=\"0\">--Todos--</option>';

    foreach ($inmuebles as $inmueble) {
        $optInmuebles.= "<option value=\"{$inmueble->tipo_inmueble}\">{$inmueble->tipo_inmueble}</option>\n";
    }

    $contenido = <<<EOSTR
      <div class="jsrequired {$delta}" id="bloque_buscador">
        <header class="title">
          <h2>Encuentra tu inmueble ideal!</h2>
        </header>
        <div class="filtros">

          <form action="/filtro" method="GET">
            <table  border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td><label for="operacion">Busco inmuebles en:</label></td>
                    <td>
                        <label class="vc">Venta <input type="radio" name="operacion" id="operacion" value="venta"/></label>
                        <label class="vc">Renta <input type="radio" name="operacion" id="operacion" value="renta" /></label> 
                    </td>
                </tr>
                <tr>
                    <td><label for="tipo_inmueble">Tipo de inmueble?</label></td>
                    <td><select name="inmueble" id="inmueble" style="width:150px;"> $optInmuebles </select></td>
                </tr>
                <tr>
                    <td><label for="estado">En donde?</label></td>
                    <td><select name="estado" id="estado" style="width:150px;"> $optEstados </select></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" value="Buscar"></td>
                </tr>
          </table>
            </form>
        </div>
        <div class="mapa"><a href="#" class="mapa_buscador"></a></div>

      </div>
EOSTR;

  $bloque = array(
    "subject" => NULL,
    "content" => $contenido
  );
  return $bloque;
}

?>
  • Have you installed and enabled the module, ensured your module is called "bloque_buscador", and cleared Drupal's cache? – Clive Mar 1 '13 at 11:26
  • Try setting "subject" to something like "Lorem ipsum". Works then? – Mołot Jun 24 '13 at 12:06
1

That is because your module_block_view() function is not written properly. the content is not passed into any of the blocks you defined in your module_block_info()

function bloque_buscador_block_view($delta = '')
{
        $block = array();
        switch ($delta) 
       {
        case 'bloque_home':
            $block['subject'] = t('Syndicate');
            $block['content'] = YOUR CONTENT IN HERE,

        );
        break;
        case 'bloque_sidebar':
            $block['subject'] = t('Syndicate');
            $block['content'] = YOUR CONTENT IN HERE,

        );
        break;
      }
    return block;
 }
| improve this answer | |
  • His module is returning proper array. It's just a bit hard to read due to heredoc most of us is not used to. – Mołot Jun 24 '13 at 11:52
  • Switching by delta is not needed if module provides only one block or uses delta in any other way to alter content between it's blocks. It is just most usual form, but as long as correct array is returned it should be all right. – Mołot Jun 24 '13 at 12:02
0

I don't see anything strange in your code in itself, especially the hook_block_view()!

Omission of the usual check on delta param in hook_block_view() is justified in your case as to my understanding that both blocks display the same content.

Beyond Clive's check points you may also try to first delete your module's block entries in Drupal's block DB table.

You can read full explanation of this suggestion in my answer to similar question:

Custom made blocks not getting displayed in Blocks page

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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