You are here

CourseObjectFulfillmentStorageSchema.php in Course 3.x

File

src/Schema/CourseObjectFulfillmentStorageSchema.php
View source
<?php

namespace Drupal\course\Schema;

use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
use Drupal\Core\Field\FieldStorageDefinitionInterface;

/**
 * Defines the course object fulfillment schema handler. Ensure that a user can
 * only have one fulfillment per course object.
 */
class CourseObjectFulfillmentStorageSchema extends SqlContentEntityStorageSchema {

  /**
   * {@inheritdoc}
   */
  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
    $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
    if ($table_name === 'course_object_fulfillment' && $storage_definition
      ->getName() == 'cofid') {
      $schema['unique keys']['coid_uid'] = [
        'coid',
        'uid',
      ];
    }
    return $schema;
  }

}

Classes

Namesort descending Description
CourseObjectFulfillmentStorageSchema Defines the course object fulfillment schema handler. Ensure that a user can only have one fulfillment per course object.