Assuming your code is running for a node page, the methods I see used most often in core/contrib modules are either using menu_get_object() or arg():
if ($node = menu_get_object()) {
// Get the nid
$nid = $node->nid;
}
or
if (arg(0) == 'node' && is_numeric(arg(1))) {
// Get the nid
$nid = arg(1);
// Load the node if you need to
$node = node_load($nid);
}
I personally prefer the first method (even though assignment in condition isn't considered a good idea by some people), but both are perfectly valid.
$alias = drupal_get_path_alias('node/37');
lando drush field-create my_content_type my_field_name,image,media_generic;
lando drush field-create my_content_type my_field_name,link_field,link_field;
lando drush field-create my_content_type my_field_name,entityreference,entityreference_autocomplete;
lando drush field-create my_content_type my_field_name,text,text_textfield;
lando drush field-create my_content_type my_field_name,text_long,text_textarea;
lando drush field-create my_content_type my_field_name,taxonomy_term_reference,options_select
lando drush eval "module_load_install('my_module_containing_hook'); my_module_containing_hook_update_7001();"
lando drush sql-query "DELETE from system where type = 'module' AND name = 'my_module_name';"
lando drush field-delete field_name -y
function hook_preprocess_html(&$variables) {
if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
$node = node_load(arg(1));
$node_type = $node->type;
}
}
From hook_preprocess_node()
$catalog_image_original = file_create_url($variables['field_catalog_image'][0]['uri']);
@see https://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way
drupal_add_js(drupal_get_path('theme', 'theme_name') . '/js/filename.js');
drupal_add_js(array(
'catalogFull' => array(
'imageUrl' => $my_variable,
),
), 'setting');
Get it in the js:
(function($) {
Drupal.behaviors.catalogFull = {
attach: function(context, settings) {
const imageUrl = Drupal.settings['catalogFull']['imageUrl'];
}
}
})(jQuery);
Node export has a feature integration but only the first 250 nodes are available. A trick mentioned here propose to add this function temporarily to limit nodes to sticky ones.
function orange_webform_extra_query_alter($query) {
if ($query->hasTag('node_export_features')) {
$query->condition('sticky', 1);
}
}