markdown Drupal 7 - 以编程方式将视图模式添加到实体

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Drupal 7 - 以编程方式将视图模式添加到实体相关的知识,希望对你有一定的参考价值。

# In a module file:

This will enable an additional view mode for use on the specified entity type(s). Many examples will show the `custom settings` here being set to TRUE. If TRUE is used then that view mode is added to all entities of the specified type regardless of if it should be on the bundle or not.

```php
/**
 * Implements hook_entity_info_alter().
 */
function HOOK_entity_info_alter(&$entity_info) {

  $entity_info['node']['view modes'] += array(
    'view_mode_machine_name' => array(
      'label' => t('View mode display name'),
      'custom settings' => FALSE,
    ),
  );

  return $entity_info;
}
```

Where "view_mode_machine_name" is the machine name of the view mode you want to add (ex: sidebar).

以上是关于markdown Drupal 7 - 以编程方式将视图模式添加到实体的主要内容,如果未能解决你的问题,请参考以下文章

markdown 以编程方式为Drupal 8中的错误页面(404等)设置自定义模板

drupal 7以编程方式登录用户

Drupal 7以编程方式将数据提交给webform

PHP Drupal(6和7):以编程方式更改活动主题

Drupal(6&7):以编程方式更改活动主题

Drupal 7:以编程方式将过滤器添加到视图中