public function YoastSeoManager::attachYoastSeoFields in Real-time SEO for Drupal 8
Attach the yoast seo fields to a target content type.
Parameters
string $entity_type: Bundle.
array $bundle: Entity type.
File
- src/
YoastSeoManager.php, line 62
Class
- YoastSeoManager
- Class YoastSeoManager.
Namespace
Drupal\yoast_seoCode
public function attachYoastSeoFields($entity_type, $bundle) {
// Attach metatag field to the target content.
$metatag_field = array(
'field_name' => 'field_meta_tags',
'field_label' => 'Meta tags',
'storage_type' => 'metatag',
'translatable' => TRUE,
);
$this->yoast_seo_field_manager
->attachField($entity_type, $bundle, $metatag_field);
// Attach yoast seo field to the target content type.
$yoast_fields = [
'field_yoast_seo' => array(
'field_name' => 'field_yoast_seo',
'field_label' => 'Real-time SEO',
'storage_type' => 'yoast_seo',
'translatable' => TRUE,
),
];
foreach ($yoast_fields as $field) {
$this->yoast_seo_field_manager
->attachField($entity_type, $bundle, $field);
}
}