示例#1
0
 /**
  * Builds a list of fields
  */
 public function fieldList()
 {
     $custom_fields = $this->storage->listAll('ds.field.');
     if (!empty($custom_fields)) {
         $rows = array();
         foreach ($custom_fields as $config) {
             $field_value = $this->config($config)->get();
             $row = array();
             $row[] = array('data' => array('#plain_text' => $field_value['label']));
             $row[] = isset($field_value['type_label']) ? $field_value['type_label'] : $this->t('Unknown');
             $row[] = $field_value['id'];
             $row[] = ucwords(str_replace('_', ' ', implode(', ', $field_value['entities'])));
             $operations = array();
             $operations['edit'] = array('title' => $this->t('Edit'), 'url' => new Url('ds.manage_field', array('field_key' => $field_value['id'])));
             $operations['delete'] = array('title' => $this->t('Delete'), 'url' => new Url('ds.delete_field', array('field_key' => $field_value['id'])));
             $this->moduleHandler->alter('ds_field_operations', $operations, $field_value);
             $row[] = array('data' => array('#type' => 'operations', '#subtype' => 'ds', '#links' => $operations));
             $rows[] = $row;
         }
         $build = array('#theme' => 'table', '#header' => array('Label', 'Type', 'Machine name', 'Entities', 'Operations'), '#rows' => $rows);
     } else {
         $build = array('#markup' => $this->t('No custom fields have been defined.'));
     }
     return $build;
 }
 /**
  * Tests that the storage supports collections.
  */
 public function testCollection()
 {
     $name = 'config_test.storage';
     $data = array('foo' => 'bar');
     $result = $this->storage->write($name, $data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($data, $this->storage->read($name));
     // Create configuration in a new collection.
     $new_storage = $this->storage->createCollection('collection.sub.new');
     $this->assertFalse($new_storage->exists($name));
     $this->assertEqual(array(), $new_storage->listAll());
     $new_storage->write($name, $data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($data, $new_storage->read($name));
     $this->assertEqual(array($name), $new_storage->listAll());
     $this->assertTrue($new_storage->exists($name));
     $new_data = array('foo' => 'baz');
     $new_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $new_storage->read($name));
     // Create configuration in another collection.
     $another_storage = $this->storage->createCollection('collection.sub.another');
     $this->assertFalse($another_storage->exists($name));
     $this->assertEqual(array(), $another_storage->listAll());
     $another_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $another_storage->read($name));
     $this->assertEqual(array($name), $another_storage->listAll());
     $this->assertTrue($another_storage->exists($name));
     // Create configuration in yet another collection.
     $alt_storage = $this->storage->createCollection('alternate');
     $alt_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $alt_storage->read($name));
     // Switch back to the collection-less mode and check the data still exists
     // add has not been touched.
     $this->assertIdentical($data, $this->storage->read($name));
     // Check that the getAllCollectionNames() method works.
     $this->assertIdentical(array('alternate', 'collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     // Check that the collections are removed when they are empty.
     $alt_storage->delete($name);
     $this->assertIdentical(array('collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     // Create configuration in collection called 'collection'. This ensures that
     // FileStorage's collection storage works regardless of its use of
     // subdirectories.
     $parent_storage = $this->storage->createCollection('collection');
     $this->assertFalse($parent_storage->exists($name));
     $this->assertEqual(array(), $parent_storage->listAll());
     $parent_storage->write($name, $new_data);
     $this->assertIdentical($result, TRUE);
     $this->assertIdentical($new_data, $parent_storage->read($name));
     $this->assertEqual(array($name), $parent_storage->listAll());
     $this->assertTrue($parent_storage->exists($name));
     $this->assertIdentical(array('collection', 'collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     $parent_storage->deleteAll();
     $this->assertIdentical(array('collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
     // Check that the having an empty collection-less storage does not break
     // anything. Before deleting check that the previous delete did not affect
     // data in another collection.
     $this->assertIdentical($data, $this->storage->read($name));
     $this->storage->delete($name);
     $this->assertIdentical(array('collection.sub.another', 'collection.sub.new'), $this->storage->getAllCollectionNames());
 }