function yoast_seo_form_node_admin_content_alter in Real-time SEO for Drupal 7
Implements hook_form_FORM_ID_alter().
Add the custom Yoast score to the overview if the user has access.
File
- ./
yoast_seo.module, line 451 - Primary hook implementations for Yoast SEO for Drupal module.
Code
function yoast_seo_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
if (user_access('use yoast seo')) {
// Add our own CSS.
drupal_add_css(drupal_get_path('module', 'yoast_seo') . '/css/yoast_seo.css');
if (!empty($form['admin']['nodes']['#options'])) {
// Get all the current options node nids.
$nids = array_keys($form['admin']['nodes']['#options']);
// Add our custom SEO score header to the admin overview.
$form['admin']['nodes']['#header']['yoast_seo'] = t('SEO score');
// For every result, we fetch the score from the database on nid.
foreach (entity_load('node', $nids) as $node) {
list($nid, , $bundle) = entity_extract_ids('node', $node);
// Check if entity has SEO availability otherwise show a message.
if (yoast_seo_entity_supports_yoast_seo('node', $bundle)) {
// Score will be either 0 or a higher int. 0 is default.
$score = yoast_seo_get_score($nid);
// Class will represent classname for current score. Like poor or bad
// it's used for theming purposes.
$class = yoast_seo_score_rating($score);
// Add Yoast score to the overview.
$form['admin']['nodes']['#options'][$nid]['yoast_seo'] = '<div id="yoast-overallscore" class="overallScore ' . $class . '"><div class="score_circle"></div></div>';
}
else {
$form['admin']['nodes']['#options'][$nid]['yoast_seo'] = '';
}
}
}
}
}