Beispiel Module in Drupal 7 erstellen?

Hey Leute,

ich bin dabei eine Drupal 7 Webseite zu erstellen. Ich möchte ein einfaches Module erstellen, wie muss ich vorgehen? Kann einer mir ein Beispiel Module zeigen?

Danke euch!

Neuen Kommentar schreiben

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Profile picture for user Guest
Permanenter Link

Für eigene Blöcke braucht man ein eigenes Modul. Es geht einfach. man braucht ein Ordner unter sites/all/modules. Und in diesem Ordner nochmal zwei Datein mit gleiche Name wie Ordner:

Ordner:
sites/all/modules/itlantik_modblocks1

Darunter 2 Files:
- itlantik_modblocks1.info
- itlantik_modblocks1.module

Inhalt von itlantik_modblocks1.info

name = "Meine Itlantik Module 1" description = "Beschreibung von Module" core = "7.x" package = "Custom Modules"

Inhalt von itlantik_modblocks1.module

/**
* Implements hook_block_info().
*/
function itlantik_modblocks1_block_info() {
$blocks['itlantik_news_side2'] = array(
'info' => t('Meine news Block für Rechte Seite'), //The name that will appear in the block list.
'cache' => DRUPAL_NO_CACHE, // or DRUPAL_CACHE_PER_ROLE, //Default
);

$blocks['itlantik_news_top'] = array(
'info' => t('Meine news Block für Header Leiste'), //The name that will appear in the block list.
'cache' => DRUPAL_NO_CACHE, // DRUPAL_CACHE_PER_ROLE, //Default
);

return $blocks;
}

function itlantik_modblocks1_block_view($delta = '') {
switch($delta){
case 'itlantik_news_side2':
$block['subject'] = t('Meine news Block für Rechte Seite');

//Retrieve and process data here.
$block['content'] = get_news_side2();
break;

case 'itlantik_news_top':
$block['subject'] = t('Meine news Block für Header Leiste');

//Retrieve and process data here.
$block['content'] = get_news_top();
break;
}

return $block;
}

function get_news_top(){

return "Content of top news";
}

function get_news_side2(){

return "Content of right news";
}

?>

Profile picture for user Guest
Permanenter Link

Kann man auch erweitere Module mit gleichem Prinzip entwickeln? Ich muss was komplexeres entwickeln und weiß leider nicht wo ich anfangen soll. Gibt es Dokumentation auf Deutsch wie man Module für Drupal 7 entwickelt?

Profile picture for user Guest
Permanenter Link

Danke für den Code! Ich hab diesen nun bei mir wie angegeben installiert.
Nun habe ich leider eine etwas dumme Frage, wo ich nicht mehr weiterkomme: wie kann ich den Block nun innerhalb von Drupal nutzen? Im Andminbereich unter "Modul" habe ich das Modul gefunden. Aber wie nutze ich es jetzt im Content. Muss ich etwas in den Views hinzufügen oder in der Rubrik Blocks?
Sorry, ich bin noch Anfänger.

Suche

Neueste Kommentare

  • 5 days 10 hours ago
    How to Renew Let’s Encrypt SSL Certificate on Plesk via Ubuntu Shell

    Let’s Encrypt will only accept a wildcard via DNS challenge. 

    If your Plesk instance can’t create the _acme-challenge.example.com TXT (external DNS), the extension can’t complete validation and will show no success. 

  • 1 week 5 days ago
    Warning: Undefined array key "url" in Drupal\Core\Asset\CssCollectionOptimizerLazy->optimizeGroup()
    Warning: Undefined array key "url" in Drupal\Core\Asset\JsCollectionOptimizerLazy->optimizeGroup() 
  • 2 weeks ago
    Server install & config : Debian 12 + Plesk + Apache + nginx + MariaDB + Solr
    sudo timedatectl set-timezone Europe/Berlin
  • 3 weeks ago
    Warning: PHP Startup: Unable to load dynamic library 'apcu.so' ... cannot open shared object file: No such file or directory

    Try this:

  • 1 month ago
    List Cronjobs for all users (via for + crontab)

    Alternative (without warnings like "no crontab for dovecot") to see all tasks:

  • 1 month ago
    Install APCu (PHP 8.1, Plesk)

    php 8.3 apcu failed

    über Plesk hat es geklappt.

     

  • 1 month ago
    Install APCu (PHP 8.1, Plesk)

     

    install:

    # sudo apt install php-dev
    
  • 1 month ago
    pecl install apcu : phpize: not found / ERROR: `phpize' failed

    phpize

    # sudo apt install php-dev
    

     

    details

  • 1 month ago
    Install APCu (PHP 8.1, Plesk)

    Problem:

  • 2 months 3 weeks ago
    Install APCu (PHP 8.1, Plesk)

    Problem: