Commit dda432db authored by lammensj's avatar lammensj Committed by Robert Ragas

Issue #2574293 by LammensJ: Can't see Yoast SEO scores in admin/content when...

Issue #2574293 by LammensJ: Can't see Yoast SEO scores in admin/content when using the Admin Views module
parent e8adbdb4
<?php
/**
* @file
* Views definitions for yoast_seo.
*/
/**
* Implements hook_views_data().
*/
function yoast_seo_views_data() {
$data = array();
$data['node']['yoast_seo_score'] = array(
'title' => t('SEO score'),
'help' => t('SEO score'),
'field' => array(
'handler' => 'yoast_seo_handler_score',
),
);
return $data;
}
<?php
class yoast_seo_handler_score extends views_handler_field {
/**
* @inheritdoc
*/
function query() {
$this->ensure_my_table();
}
/**
* Renders the field handler.
*/
function render($values) {
$output = '';
if (user_access('use yoast seo')) {
// Add our own CSS.
drupal_add_css(drupal_get_path('module', 'yoast_seo') . '/css/yoast_seo.css');
// Check if entity has SEO availability otherwise show a message.
if (yoast_seo_entity_supports_yoast_seo('node', strtolower($values->node_type))) {
// Score will be either 0 or a higher int. 0 is default.
$score = yoast_seo_get_score($values->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.
$output = '<div id="yoast-overallscore" class="overallScore ' . $class . '"><div class="score_circle"></div></div>';
}
else {
$output = '';
}
}
return $output;
}
}
\ No newline at end of file
......@@ -6,5 +6,9 @@ core = 7.x
dependencies[] = node
dependencies[] = metatag
dependencies[] = path
dependencies[] = ctools
configure = admin/config/search/yoast
; Views Handlers
files[] = views/yoast_seo_handler_score.inc
\ No newline at end of file
......@@ -37,6 +37,16 @@ function yoast_seo_menu() {
return $items;
}
/**
* Implements hook_views_api().
*/
function yoast_seo_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'yoast_seo') . '/views',
);
}
/**
* Build a FAPI array for editing meta tags.
*
......@@ -236,7 +246,10 @@ function yoast_seo_configuration_form_after_build($form, &$form_state) {
);
// Minified JS file.
drupal_add_js(yoast_seo_library_path('js-text-analysis') . '/yoast-seo.min.js', array('type' => 'external', 'scope' => 'footer'));
drupal_add_js(yoast_seo_library_path('js-text-analysis') . '/yoast-seo.min.js', array(
'type' => 'external',
'scope' => 'footer'
));
// Our own JavaScript.
drupal_add_js(drupal_get_path('module', 'yoast_seo') . '/js/yoast_seo.js');
......@@ -465,8 +478,7 @@ function yoast_seo_score_rating($score) {
break;
}
return $score_rate;
};
}
/**
* Load SEO info for multiple entities.
......@@ -736,8 +748,8 @@ function yoast_seo_configuration_save($entity_type, $entity_id, $revision_id, $s
AND (entity_id = :id)
AND (revision_id = :revision)",
array(
':type' => $entity_type,
':id' => $entity_id,
':type' => $entity_type,
':id' => $entity_id,
':revision' => $revision_id,
))->fetchAllKeyed();
foreach ($languages as $oldlang => $empty) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment