You are here

public function EntityTypeInfo::getFormattedAmpEnabledTypes in Accelerated Mobile Pages (AMP) 8.3

Same name and namespace in other branches
  1. 8 src/EntityTypeInfo.php \Drupal\amp\EntityTypeInfo::getFormattedAmpEnabledTypes()
  2. 8.2 src/EntityTypeInfo.php \Drupal\amp\EntityTypeInfo::getFormattedAmpEnabledTypes()

Returns a formatted list of AMP-enabled content types.

Return value

array A list of content types that provides the following:

  • Each content type enabled on the site.
  • The enabled/disabled status for each content type.
  • A link to enable/disable view modes for each content type.
  • A link to configure the AMP view mode, if enabled.

File

src/EntityTypeInfo.php, line 104

Class

EntityTypeInfo
Service class for retrieving and manipulating entity type information.

Namespace

Drupal\amp

Code

public function getFormattedAmpEnabledTypes() {
  $enabled_types = !empty($this
    ->getAmpEnabledTypes()) ? $this
    ->getAmpEnabledTypes() : [];
  $node_types = node_type_get_names();
  $destination = Url::fromRoute("amp.settings")
    ->toString();
  $rows = [];
  foreach ($node_types as $bundle => $label) {
    $configure = Url::fromRoute("entity.entity_view_display.node.view_mode", [
      'node_type' => $bundle,
      'view_mode_name' => 'amp',
    ], [
      'query' => [
        'destination' => $destination,
      ],
    ])
      ->toString();
    $enable_disable = Url::fromRoute("entity.entity_view_display.node.default", [
      'node_type' => $bundle,
    ], [
      'query' => [
        'destination' => $destination,
      ],
    ])
      ->toString();
    $configure_link = t('<a href=":configure">configure</a>', [
      ':configure' => $configure,
    ]);
    $enable_link = t('<a href=":enable_disable">enable</a>', [
      ':enable_disable' => $enable_disable,
    ]);
    $disable_link = t('<a href=":enable_disable">disable</a>', [
      ':enable_disable' => $enable_disable,
    ]);
    if (in_array($bundle, $enabled_types)) {
      $rows[] = [
        $label,
        'X',
        $configure_link,
        $disable_link,
      ];
    }
    else {
      $rows[] = [
        $label,
        '',
        '',
        $enable_link,
      ];
    }
  }
  return $rows;
}