drupal
This is an old revision of the document!
Drupal
d7
d7 base modules
drush dl module_filter admin_menu views ctools pathauto sitemap bootstrap jquery_update date devel metatag xmlsitemap libraries transliteration token field_group autocomplete_deluxe entity rules calendar date_ical
d7 link ajax call
function mymodule_menu() {
$items['mymodule/%'] = array(
'title' => 'My module callback',
'type' => MENU_CALLBACK,
'page callback' => 'mymodule_callback',
'page arguments' => array(1),
'access callback' => TRUE,
);
}
function mymodule_node_view($node, $build_mode = 'full') {
if ($node->type == 'mynodetype' && $build_mode == 'full') {
$node->content['mylink'] = array(
'#type' => 'link',
'#title' => t('Do the magic'),
'#href' => 'mymodule/'.$node->nid,
'#prefix' => '<div id="mylink">',
'#suffix' => '</div><div id="mylink-ajax-result"></div>',
'#ajax' => array(
'effect' => 'fade',
),
);
}
}
function mymodule_callback($nid) {
$output = 'Yeah';
$commands = array();
$commands[] = ajax_command_replace('#mylink-ajax-result', $output);
$page = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($page);
}
d7 quick vertical tabs
$form['main_fieldset'] = array( '#type' => 'fieldset', '#title' => 'my fieldset' ); $form['main_fieldset']['mytabs'] = array( '#type' => 'vertical_tabs', ); $form['main_fieldset']['other'] = array( '#type' => 'fieldset', '#title' => 'my fieldset', '#group' => 'mytabs' );
d7 relations
Here are some pieces of code to play with nodes and “relation” module.
function relation_new_child_node_view($node, $build_mode = 'full') {
if ($build_mode == 'full') {
// get available relations
$relation_types = relation_get_available_types('node', $node->type, 'target');
if ($relation_types) {
$content = array();
foreach ($relation_types as $relation_type) {
// get available node types
$nodes_types = array();
$items = array();
foreach ($relation_type->source_bundles as $source_bundle) {
$values = explode(':', $source_bundle);
$nodes_types[$values[1]] = node_type_get_name($values[1]);
$items[] = l(
t('Create a new !type', array('!type' => $nodes_types[$values[1]])),
'node/add/' . $values[1],
array(
'query' => array(
'destination' => 'node/' . $node->nid,
'rt' => $relation_type->relation_type,
'nid' => $node->nid
)
)
);
}
if (!empty($items)) {
$content['relation_links'] = array(
'#markup' => theme_item_list(array(
'items' => $items,
'title' => t('Create related content'),
'type' => 'ul',
'attributes' => array()
))
);
}
// get related content
$query = relation_query('node', $node->nid);
$query->entityCondition('bundle', $relation_type->relation_type);
$results = $query->execute();
if ($results) {
// get the related nodes
$related_nodes = array();
foreach ($results as $result) {
$relation = relation_load($result->rid);
$entities = field_get_items('relation', $relation, 'endpoints');
$related_nodes[] = node_load((int)$entities[0]['entity_id']);
}
if (!empty($related_nodes)) {
$nodes_types = array_unique($nodes_types);
foreach ($nodes_types as $node_type => $node_type_name) {
$items = array();
foreach ($related_nodes as $related_node) {
if ($related_node->type == $node_type) {
$items[] = l($related_node->title, 'node/' . $related_node->nid, array('attributes' => array('title' => $related_node->title)));
}
}
if (!empty($items)) {
$content['related_links'][$node_type] = array(
'#markup' => theme_item_list(array(
'items' => $items,
'title' => $node_type_name,
'type' => 'ul',
'attributes' => array()
))
);
}
}
}
}
}
if (!empty($content['related_links'])) {
$node->content[] = $content['related_links'];
}
if (!empty($content['relation_links'])) {
$node->content[] = $content['relation_links'];
}
}
}
}
function relation_new_child_node_insert($node) {
dsm('passed');
if ((isset($_GET['rt']) && !empty($_GET['rt'])) && (isset($_GET['nid']) && !empty($_GET['nid']))) {
$endpoints = array();
$endpoints[] = array('entity_type' => 'node', 'entity_id' => $node->nid);
$endpoints[] = array('entity_type' => 'node', 'entity_id' => $_GET['nid']);
$new_relation = relation_create($_GET['rt'], $endpoints);
if ($rid = relation_save($new_relation)) {
drupal_set_message(t('Relation created'), 'status', FALSE);
}
else {
drupal_set_message(t('Creating relation failed'), 'warning', FALSE);
}
}
}
d8
d8 install
sudo apt install php-gd sudo apt install php-mbstring composer create-project drupal/recommended-project:8.x d8test
drupal.1635854838.txt.gz · Last modified: (external edit)
