Commit 8da25f6f authored by larowlan's avatar larowlan

Issue #2927563 by tstoeckler, amateescu: Aggregator feed "refresh" field...

Issue #2927563 by tstoeckler, amateescu: Aggregator feed "refresh" field should have a default value
parent 7d1545b3
...@@ -40,3 +40,13 @@ function aggregator_update_8200() { ...@@ -40,3 +40,13 @@ function aggregator_update_8200() {
$field_definition->setRequired(TRUE); $field_definition->setRequired(TRUE);
$definition_update_manager->updateFieldStorageDefinition($field_definition); $definition_update_manager->updateFieldStorageDefinition($field_definition);
} }
/**
* Add a default value for the 'Refresh' field for aggregator feed entities.
*/
function aggregator_update_8501() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$field_definition = $definition_update_manager->getFieldStorageDefinition('refresh', 'aggregator_feed');
$field_definition->setDefaultValue(3600);
$definition_update_manager->updateFieldStorageDefinition($field_definition);
}
...@@ -47,10 +47,7 @@ public static function create(ContainerInterface $container) { ...@@ -47,10 +47,7 @@ public static function create(ContainerInterface $container) {
* A form array as expected by drupal_render(). * A form array as expected by drupal_render().
*/ */
public function feedAdd() { public function feedAdd() {
$feed = $this->entityManager()->getStorage('aggregator_feed') $feed = $this->entityManager()->getStorage('aggregator_feed')->create();
->create([
'refresh' => 3600,
]);
return $this->entityFormBuilder()->getForm($feed); return $this->entityFormBuilder()->getForm($feed);
} }
......
...@@ -168,6 +168,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ...@@ -168,6 +168,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['refresh'] = BaseFieldDefinition::create('list_integer') $fields['refresh'] = BaseFieldDefinition::create('list_integer')
->setLabel(t('Update interval')) ->setLabel(t('Update interval'))
->setDescription(t('The length of time between feed updates. Requires a correctly configured cron maintenance task.')) ->setDescription(t('The length of time between feed updates. Requires a correctly configured cron maintenance task.'))
->setDefaultValue(3600)
->setSetting('unsigned', TRUE) ->setSetting('unsigned', TRUE)
->setRequired(TRUE) ->setRequired(TRUE)
->setSetting('allowed_values', $period) ->setSetting('allowed_values', $period)
......
...@@ -38,4 +38,21 @@ public function testSourceFeedRequired() { ...@@ -38,4 +38,21 @@ public function testSourceFeedRequired() {
$this->assertTrue($field_definition->isRequired()); $this->assertTrue($field_definition->isRequired());
} }
/**
* Tests that the 'Update interval' field has a default value.
*/
public function testUpdateIntervalDefaultValue() {
// Check that the 'refresh' field does not have a default value prior to the
// update.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('refresh', 'aggregator_feed');
$this->assertSame([], $field_definition->getDefaultValueLiteral());
// Run updates.
$this->runUpdates();
// Check that the 'refresh' has a default value now.
$field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('refresh', 'aggregator_feed');
$this->assertSame([['value' => 3600]], $field_definition->getDefaultValueLiteral());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment