You are here

public function YoastSeoManager::attachFieldHandlerToContentView in Real-time SEO for Drupal 8

Attach a field handler for yoast seo in the content view.

File

src/YoastSeoManager.php, line 154

Class

YoastSeoManager
Class YoastSeoManager.

Namespace

Drupal\yoast_seo

Code

public function attachFieldHandlerToContentView() {
  $content_view = Views::getView('content');
  if ($content_view) {
    $display_id = 'page_1';
    $handlers = $content_view
      ->getHandlers('field', $display_id);
    if (!isset($handlers['field_yoast_seo'])) {
      $content_view
        ->addHandler($display_id, 'field', 'node__field_yoast_seo', 'field_yoast_seo', [
        'type' => 'yoastseo_formatter',
      ], 'field_yoast_seo');
      $content_view
        ->save();
    }
  }
}