当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldStorageDefinitionInterface::getDisplayOptions方法代码示例

本文整理汇总了PHP中Drupal\Core\Field\FieldStorageDefinitionInterface::getDisplayOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldStorageDefinitionInterface::getDisplayOptions方法的具体用法?PHP FieldStorageDefinitionInterface::getDisplayOptions怎么用?PHP FieldStorageDefinitionInterface::getDisplayOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Field\FieldStorageDefinitionInterface的用法示例。


在下文中一共展示了FieldStorageDefinitionInterface::getDisplayOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createFormDisplay

  /**
   * Create a form display for a newly clone field.
   *
   * This function attempts to use same setting settings as the source field.
   *
   * @param \Drupal\scheduled_updates\ScheduledUpdateTypeInterface $scheduled_update_type
   * @param $field_name
   * @param $field_config_id
   * @param $entity_type
   * @param $definition
   *  Source field definition
   * @param $new_field_name
   */
  protected function createFormDisplay(ScheduledUpdateTypeInterface $scheduled_update_type, $field_config_id, FieldStorageDefinitionInterface $definition, $new_field_name) {
    $destination_bundle = $scheduled_update_type->id();
    $field_name = $definition->getName();
    $entity_type = $scheduled_update_type->getUpdateEntityType();
    /** @var EntityFormDisplay $destination_form_display */
    $destination_form_display = EntityFormDisplay::load("scheduled_update.$destination_bundle.default");
    if (empty($destination_form_display)) {
      $destination_form_display = EntityFormDisplay::create([
        'targetEntityType' => 'scheduled_update',
        'bundle' => $destination_bundle,
        'mode' => 'default',
        'status' => TRUE,
      ]);
    }
    $display_options = [];
    if ($field_config_id) {
      $parts = explode('.', $field_config_id);
      $source_bundle = $parts[1];
      /** @var EntityFormDisplay $source_form_display */
      $source_form_display = EntityFormDisplay::load("$entity_type.$source_bundle.default");

      $display_options = $source_form_display->getComponent($field_name);
    }
    else {
      if ($definition instanceof BaseFieldDefinition) {
        $display_options = $definition->getDisplayOptions('form');
        if (empty($display_options)) {
          if ($definition->getType()) {
            // Provide default display for base boolean fields that don't have their own form display
            $display_options = [
              'type' => 'boolean_checkbox',
              'settings' => ['display_label' => TRUE],
            ];
          }
        }
      }
    }
    if (empty($display_options)) {
      $display_options = [];
    }
    if ($destination_form_display) {
      $destination_form_display->setComponent($new_field_name, $display_options);
      $destination_form_display->save();
    }
    else {
      // Alert user if display options could not be created.
      // @todo Create default display options even none on source.
      drupal_set_message(
        $this->t(
          'Form display options could not be created for @field they will have to be created manually.',
          ['@field' => $field_name]
        ),
        'warning');
    }
  }
开发者ID:joebachana,项目名称:usatne,代码行数:68,代码来源:FieldManager.php


注:本文中的Drupal\Core\Field\FieldStorageDefinitionInterface::getDisplayOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。