Skip to content
Snippets Groups Projects
Commit a039b4df authored by Neil Drumm's avatar Neil Drumm :wave:
Browse files

Keep the output rendering in the calling code, move project type logic into the function

parent 9d94e032
No related branches found
No related tags found
No related merge requests found
......@@ -3931,49 +3931,37 @@ function drupalorg_node_access($node, $op, $account) {
}
}
function drupalorg_composer_command_display($node_wrapper, $download_table) {
// $node_drupal_wrapper = entity_metadata_wrapper('node', $node_wrapper);
$namespace = project_composer_get_project_namespace($node_wrapper->field_release_project->raw(), $node_wrapper->field_release_category->value());
if ($namespace != '') {
if ($node_wrapper->field_release_build_type->value() === 'dynamic') {
$version = project_composer_release_version($node_wrapper) . '-dev';
}
else {
$version = '^' . $node_wrapper->field_release_version_major->value() . '.' . $node_wrapper->field_release_version_minor->value();
}
// Add stability flag if needed.
if ($version_extra = $node_wrapper->field_release_version_extra->value()) {
$version_extra = preg_replace('/[0-9]+$/', '', $version_extra);
if ($version_extra === 'rc') {
$version_extra = 'RC';
}
$version .= '@' . $version_extra;
}
// Add core requirement.
$core_version_req = drupalorg_release_core_version_requirement($node_wrapper);
$node->content['drupalorg_composer_install'] = [
'#markup' => '<h2>Install</h2>' . $core_version_req['#markup'] . '<br><code class="language-bash composer-command">' . t('$ composer require \'drupal/@namespace:@version\'</code><br>' . '
<a href="/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies">Using Composer to manage Drupal site dependencies</a>', [
'@namespace' => $namespace,
'@version' => $version,
]) . '</code>',
];
if ($node_wrapper->getBundle() == 'project_release' && empty($download_table)) {
return $node->content['drupalorg_composer_install'];
}
/**
* Render the composer require command for a release node.
*/
function drupalorg_composer_command_display(EntityDrupalWrapper $node_wrapper) {
switch ($node_wrapper->field_release_project->getBundle()) {
case 'project_module':
case 'project_theme':
if ($namespace = project_composer_get_project_namespace($node_wrapper->field_release_project->raw(), $node_wrapper->field_release_category->value())) {
if ($node_wrapper->field_release_build_type->value() === 'dynamic') {
$version = project_composer_release_version($node_wrapper) . '-dev';
}
else {
$version = '^' . $node_wrapper->field_release_version_major->value() . '.' . $node_wrapper->field_release_version_minor->value();
}
// Add stability flag if needed.
if ($version_extra = $node_wrapper->field_release_version_extra->value()) {
$version_extra = preg_replace('/[0-9]+$/', '', $version_extra);
if ($version_extra === 'rc') {
$version_extra = 'RC';
}
$version .= '@' . $version_extra;
}
if ($download_table == 1) {
$output = '<div class="dl-table">Install: <code class="language-bash composer-command">' . t('$ composer require \'drupal/@namespace:@version\'</code></div>', [
return '<code class="language-bash composer-command">' . t('$ composer require \'drupal/@namespace:@version\'', [
'@namespace' => $namespace,
'@version' => $version,
]) . '</code>';
return $output;
}
}
}
}
/**
* Implements hook_node_view().
*/
......@@ -4439,11 +4427,10 @@ function drupalorg_node_view($node, $view_mode = 'full') {
}
// Install with Composer information.
switch ($project_type) {
case 'project_module':
case 'project_theme':
$node->content['drupalorg_composer_install'] = drupalorg_composer_command_display(entity_metadata_wrapper('node', $node),0);
break;
if ($composer_command = drupalorg_composer_command_display($wrapper)) {
$node->content['drupalorg_composer_install'] = [
'#markup' => '<h2>' . t('Install') . '</h2>' . drupalorg_release_core_version_requirement($wrapper)['#markup'] . '<br>' . $composer_command . '<br><small>' . l(t('Using Composer to manage Drupal site dependencies'), 'docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies') . '</small>',
];
}
}
}
......
......@@ -15,20 +15,12 @@ class drupalorg_handler_release_branch_info extends views_handler_field_entity {
];
static $releases_seen = [];
static $has_api_tid_regex;
$output = '';
if ($release_wrapper = entity_metadata_wrapper('node', $this->get_value($values))) {
$project_node = node_load($values->_field_data['nid_1']['entity']->field_release_project['und'][0]['target_id']);
$project_type = $project_node->type;
$output = '';
// Install with Composer information.
if ($project_type != '' && !($release_wrapper->field_release_build_type->value() === 'dynamic')) {
switch ($project_type) {
case 'project_module':
case 'project_theme':
$output = drupalorg_composer_command_display ($release_wrapper, 1);
}
}
else {
$output = '';
if ($release_wrapper->field_release_build_type->value() === 'static' && $release_wrapper->field_release_category->value() === 'current' && ($composer_command = drupalorg_composer_command_display($release_wrapper))) {
$output .= '<div class="install">' . t('Install:') . ' ' . $composer_command . '</div>';
}
// Find a pre-release, if there is one.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment