You are here

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

Same name and namespace in other branches
  1. 8.3 src/EntityTypeInfo.php \Drupal\amp\EntityTypeInfo::getFormattedAmpEnabledTypes()
  2. 8 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() : array();
  $node_types = node_type_get_names();
  $node_status_list = array();
  $destination = Url::fromRoute("amp.settings")
    ->toString();
  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();
    if (in_array($bundle, $enabled_types)) {
      $node_status_list[] = t('@label is <em>enabled</em>: <a href=":configure">Configure AMP view mode</a> or <a href=":enable_disable">Disable AMP display</a>', array(
        '@label' => $label,
        ':configure' => $configure,
        ':enable_disable' => $enable_disable,
      ));
    }
    else {
      $node_status_list[] = t('@label is <em>disabled</em>: <a href=":enable_disable">Enable AMP in Custom Display Settings</a>', array(
        '@label' => $label,
        ':enable_disable' => $enable_disable,
      ));
    }
  }
  return $node_status_list;
}