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


PHP FieldStorageDefinitionInterface::getSchema方法代码示例

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


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

示例1: getDedicatedTableSchema

 /**
  * Gets the SQL schema for a dedicated table.
  *
  * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  *   The field storage definition.
  * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type
  *   (optional) The entity type definition. Defaults to the one returned by
  *   the entity manager.
  *
  * @return array
  *   The schema definition for the table with the following keys:
  *   - fields: The schema definition for the each field columns.
  *   - indexes: The schema definition for the indexes.
  *   - unique keys: The schema definition for the unique keys.
  *   - foreign keys: The schema definition for the foreign keys.
  *
  * @throws \Drupal\Core\Field\FieldException
  *   Exception thrown if the schema contains reserved column names.
  *
  * @see hook_schema()
  */
 protected function getDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, ContentEntityTypeInterface $entity_type = NULL)
 {
     $description_current = "Data storage for {$storage_definition->getTargetEntityTypeId()} field {$storage_definition->getName()}.";
     $description_revision = "Revision archive storage for {$storage_definition->getTargetEntityTypeId()} field {$storage_definition->getName()}.";
     $id_definition = $this->fieldStorageDefinitions[$this->entityType->getKey('id')];
     if ($id_definition->getType() == 'integer') {
         $id_schema = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The entity id this data is attached to');
     } else {
         $id_schema = array('type' => 'varchar_ascii', 'length' => 128, 'not null' => TRUE, 'description' => 'The entity id this data is attached to');
     }
     // Define the revision ID schema.
     if (!$this->entityType->isRevisionable()) {
         $revision_id_schema = $id_schema;
         $revision_id_schema['description'] = 'The entity revision id this data is attached to, which for an unversioned entity type is the same as the entity id';
     } elseif ($this->fieldStorageDefinitions[$this->entityType->getKey('revision')]->getType() == 'integer') {
         $revision_id_schema = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The entity revision id this data is attached to');
     } else {
         $revision_id_schema = array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'description' => 'The entity revision id this data is attached to');
     }
     $data_schema = array('description' => $description_current, 'fields' => array('bundle' => array('type' => 'varchar_ascii', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The field instance bundle to which this row belongs, used when deleting a field instance'), 'deleted' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'description' => 'A boolean indicating whether this data item has been deleted'), 'entity_id' => $id_schema, 'revision_id' => $revision_id_schema, 'langcode' => array('type' => 'varchar_ascii', 'length' => 32, 'not null' => TRUE, 'default' => '', 'description' => 'The language code for this data item.'), 'delta' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The sequence number for this data item, used for multi-value fields')), 'primary key' => array('entity_id', 'deleted', 'delta', 'langcode'), 'indexes' => array('bundle' => array('bundle'), 'revision_id' => array('revision_id')));
     // Check that the schema does not include forbidden column names.
     $schema = $storage_definition->getSchema();
     $properties = $storage_definition->getPropertyDefinitions();
     $table_mapping = $this->storage->getTableMapping();
     if (array_intersect(array_keys($schema['columns']), $table_mapping->getReservedColumns())) {
         throw new FieldException("Illegal field column names on {$storage_definition->getName()}");
     }
     // Add field columns.
     foreach ($schema['columns'] as $column_name => $attributes) {
         $real_name = $table_mapping->getFieldColumnName($storage_definition, $column_name);
         $data_schema['fields'][$real_name] = $attributes;
         // A dedicated table only contain rows for actual field values, and no
         // rows for entities where the field is empty. Thus, we can safely
         // enforce 'not null' on the columns for the field's required properties.
         $data_schema['fields'][$real_name]['not null'] = $properties[$column_name]->isRequired();
     }
     // Add indexes.
     foreach ($schema['indexes'] as $index_name => $columns) {
         $real_name = $this->getFieldIndexName($storage_definition, $index_name);
         foreach ($columns as $column_name) {
             // Indexes can be specified as either a column name or an array with
             // column name and length. Allow for either case.
             if (is_array($column_name)) {
                 $data_schema['indexes'][$real_name][] = array($table_mapping->getFieldColumnName($storage_definition, $column_name[0]), $column_name[1]);
             } else {
                 $data_schema['indexes'][$real_name][] = $table_mapping->getFieldColumnName($storage_definition, $column_name);
             }
         }
     }
     // Add unique keys.
     foreach ($schema['unique keys'] as $index_name => $columns) {
         $real_name = $this->getFieldIndexName($storage_definition, $index_name);
         foreach ($columns as $column_name) {
             // Unique keys can be specified as either a column name or an array with
             // column name and length. Allow for either case.
             if (is_array($column_name)) {
                 $data_schema['unique keys'][$real_name][] = array($table_mapping->getFieldColumnName($storage_definition, $column_name[0]), $column_name[1]);
             } else {
                 $data_schema['unique keys'][$real_name][] = $table_mapping->getFieldColumnName($storage_definition, $column_name);
             }
         }
     }
     // Add foreign keys.
     foreach ($schema['foreign keys'] as $specifier => $specification) {
         $real_name = $this->getFieldIndexName($storage_definition, $specifier);
         $data_schema['foreign keys'][$real_name]['table'] = $specification['table'];
         foreach ($specification['columns'] as $column_name => $referenced) {
             $sql_storage_column = $table_mapping->getFieldColumnName($storage_definition, $column_name);
             $data_schema['foreign keys'][$real_name]['columns'][$sql_storage_column] = $referenced;
         }
     }
     $dedicated_table_schema = array($table_mapping->getDedicatedDataTableName($storage_definition) => $data_schema);
     // If the entity type is revisionable, construct the revision table.
     $entity_type = $entity_type ?: $this->entityType;
     if ($entity_type->isRevisionable()) {
         $revision_schema = $data_schema;
         $revision_schema['description'] = $description_revision;
         $revision_schema['primary key'] = array('entity_id', 'revision_id', 'deleted', 'delta', 'langcode');
         $revision_schema['fields']['revision_id']['not null'] = TRUE;
//.........这里部分代码省略.........
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:101,代码来源:SqlContentEntityStorageSchema.php

示例2: _fieldSqlSchema

 /**
  * Gets the SQL table schema.
  *
  * @private Calling this function circumvents the entity system and is
  * strongly discouraged. This function is not considered part of the public
  * API and modules relying on it might break even in minor releases.
  *
  * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  *   The field storage definition.
  * @param array $schema
  *   The field schema array. Mandatory for upgrades, omit otherwise.
  * @param bool $deleted
  *   (optional) Whether the schema of the table holding the values of a
  *   deleted field should be returned.
  *
  * @return array
  *   The same as a hook_schema() implementation for the data and the
  *   revision tables.
  *
  * @see hook_schema()
  */
 public static function _fieldSqlSchema(FieldStorageDefinitionInterface $storage_definition, array $schema = NULL, $deleted = FALSE)
 {
     $description_current = "Data storage for {$storage_definition->getTargetEntityTypeId()} field {$storage_definition->getName()}.";
     $description_revision = "Revision archive storage for {$storage_definition->getTargetEntityTypeId()} field {$storage_definition->getName()}.";
     $entity_type_id = $storage_definition->getTargetEntityTypeId();
     $entity_manager = \Drupal::entityManager();
     $entity_type = $entity_manager->getDefinition($entity_type_id);
     $definitions = $entity_manager->getBaseFieldDefinitions($entity_type_id);
     // Define the entity ID schema based on the field definitions.
     $id_definition = $definitions[$entity_type->getKey('id')];
     if ($id_definition->getType() == 'integer') {
         $id_schema = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The entity id this data is attached to');
     } else {
         $id_schema = array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'description' => 'The entity id this data is attached to');
     }
     // Define the revision ID schema, default to integer if there is no revision
     // ID.
     $revision_id_definition = $entity_type->hasKey('revision') ? $definitions[$entity_type->getKey('revision')] : NULL;
     if (!$revision_id_definition || $revision_id_definition->getType() == 'integer') {
         $revision_id_schema = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'description' => 'The entity revision id this data is attached to, or NULL if the entity type is not versioned');
     } else {
         $revision_id_schema = array('type' => 'varchar', 'length' => 128, 'not null' => FALSE, 'description' => 'The entity revision id this data is attached to, or NULL if the entity type is not versioned');
     }
     $current = array('description' => $description_current, 'fields' => array('bundle' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The field instance bundle to which this row belongs, used when deleting a field instance'), 'deleted' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'description' => 'A boolean indicating whether this data item has been deleted'), 'entity_id' => $id_schema, 'revision_id' => $revision_id_schema, 'langcode' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '', 'description' => 'The language code for this data item.'), 'delta' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The sequence number for this data item, used for multi-value fields')), 'primary key' => array('entity_id', 'deleted', 'delta', 'langcode'), 'indexes' => array('bundle' => array('bundle'), 'deleted' => array('deleted'), 'entity_id' => array('entity_id'), 'revision_id' => array('revision_id'), 'langcode' => array('langcode')));
     if (!$schema) {
         $schema = $storage_definition->getSchema();
     }
     // Add field columns.
     foreach ($schema['columns'] as $column_name => $attributes) {
         $real_name = static::_fieldColumnName($storage_definition, $column_name);
         $current['fields'][$real_name] = $attributes;
     }
     // Add unique keys.
     foreach ($schema['unique keys'] as $unique_key_name => $columns) {
         $real_name = static::_fieldIndexName($storage_definition, $unique_key_name);
         foreach ($columns as $column_name) {
             $current['unique keys'][$real_name][] = static::_fieldColumnName($storage_definition, $column_name);
         }
     }
     // Add indexes.
     foreach ($schema['indexes'] as $index_name => $columns) {
         $real_name = static::_fieldIndexName($storage_definition, $index_name);
         foreach ($columns as $column_name) {
             // Indexes can be specified as either a column name or an array with
             // column name and length. Allow for either case.
             if (is_array($column_name)) {
                 $current['indexes'][$real_name][] = array(static::_fieldColumnName($storage_definition, $column_name[0]), $column_name[1]);
             } else {
                 $current['indexes'][$real_name][] = static::_fieldColumnName($storage_definition, $column_name);
             }
         }
     }
     // Add foreign keys.
     foreach ($schema['foreign keys'] as $specifier => $specification) {
         $real_name = static::_fieldIndexName($storage_definition, $specifier);
         $current['foreign keys'][$real_name]['table'] = $specification['table'];
         foreach ($specification['columns'] as $column_name => $referenced) {
             $sql_storage_column = static::_fieldColumnName($storage_definition, $column_name);
             $current['foreign keys'][$real_name]['columns'][$sql_storage_column] = $referenced;
         }
     }
     // Construct the revision table.
     $revision = $current;
     $revision['description'] = $description_revision;
     $revision['primary key'] = array('entity_id', 'revision_id', 'deleted', 'delta', 'langcode');
     $revision['fields']['revision_id']['not null'] = TRUE;
     $revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';
     return array(static::_fieldTableName($storage_definition) => $current, static::_fieldRevisionTableName($storage_definition) => $revision);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:90,代码来源:ContentEntityDatabaseStorage.php


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