Skip to content
Snippets Groups Projects

Issue #3279150: Remove a duplicate updateYamlToEntity() in K8sContentForm

6 files
+ 0
254
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -6,7 +6,6 @@ use Drupal\cloud\Form\CloudContentForm;
use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface;
use Drupal\cloud\Service\EntityLinkRendererInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
@@ -19,7 +18,6 @@ use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\k8s\Entity\K8sSchedule;
use Drupal\cloud\Service\CloudServiceInterface;
use Drupal\k8s\Service\K8sOperationsServiceInterface;
use Drupal\k8s\Service\K8sServiceException;
@@ -234,72 +232,6 @@ abstract class K8sContentForm extends CloudContentForm implements K8sContentForm
parent::save($form, $form_state);
}
/**
* Save the yaml of the entity detail.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
protected function saveYamlsOfEntityDetail(FormStateInterface $form_state): bool {
$yamls = $this->k8sService->decodeMultipleDocYaml($this->entity->getDetail());
foreach ($yamls ?: [] as $yaml) {
if (empty($yaml)) {
continue;
}
// The process of saving each yaml to the entity
// is implemented by saveYamlInEntity().
if (empty($this->updateYamlToEntity($form_state, $yaml))) {
return FALSE;
}
if (!empty($form_state->getValue('enable_time_scheduler'))) {
$timestamp = time();
$start_hour = $form_state->getValue('start_hour');
$start_minute = $form_state->getValue('start_minute');
$stop_hour = $form_state->getValue('stop_hour');
$stop_minute = $form_state->getValue('stop_minute');
$name = $yaml['metadata']['name'];
$schedule = K8sSchedule::create([
'cloud_context' => $this->entity->getCloudContext(),
'name' => $this->entity->getNamespace() . '_' . $name,
'kind' => $yaml['kind'],
'namespace_name' => $this->entity->getNamespace(),
'resource_name' => $name,
'start_hour' => $start_hour,
'start_minute' => $start_minute,
'start_time' => $this->getTimeFormat($start_hour, $start_minute),
'stop_hour' => $stop_hour,
'stop_minute' => $stop_minute,
'stop_time' => $this->getTimeFormat($stop_hour, $stop_minute),
'manifest' => Yaml::encode($yaml),
'created' => $timestamp,
'changed' => $timestamp,
'refreshed' => $timestamp,
]);
$schedule->save();
$this->messenger->addStatus($this->t('The @type %label has been created.', [
'@type' => $schedule->getEntityType()->getSingularLabel(),
'%label' => $schedule->toLink($schedule->getName())->toString(),
]));
$this->logOperationMessage($schedule, 'created');
}
}
return TRUE;
}
/**
* Update yaml information to entity.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $yaml
* The yaml.
*/
abstract protected function updateYamlToEntity(FormStateInterface $form_state, array $yaml): bool;
/**
* Copy values from #type=item elements to its original element type.
*
Loading