You are here

public function Table::dropField in Data 8

Delete a field.

Throws

DataException

File

src/Table.php, line 482

Class

Table
Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.

Namespace

Drupal\data

Code

public function dropField($field) {
  $success = \Drupal::database()
    ->schema()
    ->dropField($this->name, $field);
  if ($success) {
    $schema = $this->table_schema;
    unset($schema['fields'][$field]);
    $meta = $this->meta;
    unset($meta['fields'][$field]);
    $this
      ->update(array(
      'table_schema' => $schema,
    ), array(
      'meta' => $meta,
    ));
    drupal_get_schema($this->name, TRUE);
    return;
  }
  throw new DataException(t('Cannot drop field.'));
}