Commit a7d1fe66 authored by Kingdutch's avatar Kingdutch

Move is_new check to the server side

parent 87acb041
......@@ -16,11 +16,6 @@
throw 'No settings specified for the YoastSEO analysis library.';
}
// TODO: This should be set on the server side to make it work for all entity types.
if (settings.path && settings.path.currentPath.indexOf('node/add') !== -1) {
settings.yoast_seo.is_new = true;
}
$('body', context).once('realtime-seo').each(function () {
// TODO: This fails if there are multiple forms.
var $form = $('form').first();
......
......@@ -4,6 +4,7 @@ namespace Drupal\yoast_seo\Plugin\Field\FieldWidget;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -123,12 +124,23 @@ class YoastSeoWidget extends WidgetBase implements ContainerFactoryPluginInterfa
'#output_target_id' => self::$jsTargets['output_target_id'],
];
$js_confg = $this->getJavaScriptConfiguration();
$js_config = $this->getJavaScriptConfiguration();
$js_confg['fields']['focus_keyword'] = $element['yoast_seo']['focus_keyword']['#id'];
$js_confg['fields']['seo_status'] = $element['yoast_seo']['status']['#id'];
$js_config['fields']['focus_keyword'] = $element['yoast_seo']['focus_keyword']['#id'];
$js_config['fields']['seo_status'] = $element['yoast_seo']['status']['#id'];
$element['#attached']['drupalSettings']['yoast_seo'] = $js_confg;
$form_object = $form_state->getFormObject();
if ($form_object instanceof EntityForm) {
$js_config['is_new'] = $form_object->getEntity()->isNew();
}
else {
// If we aren't working with an entity we assume whatever we are working
// with is new.
$js_config['is_new'] = TRUE;
}
$element['#attached']['drupalSettings']['yoast_seo'] = $js_config;
return $element;
}
......
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