trimString($values['name'], 255); } // Start a new log entity with the provided values. /** @var \Drupal\log\Entity\LogInterface $log */ $log = Log::create($values); // If quantity measurements are provided, reference them from the log. if (!empty($values['quantity'])) { foreach ($values['quantity'] as $qty) { // If the quantity is an array of values, pass it to createQuantity. if (is_array($qty)) { $log->quantity[] = $this->createQuantity($qty, $log->bundle()); } // Otherwise, add it directly to the log. else { $log->quantity[] = $qty; } } } // If not specified, set the log's status to "done". if (!isset($values['status'])) { $log->status = 'done'; } // Track which quick form created the entity. $log->quick[] = $this->getQuickId(); // Save the log. $log->save(); // Display a message with a link to the log. $message = $this->t('Log created: @name', [':url' => $log->toUrl()->toString(), '@name' => $log->label()]); $this->messenger->addStatus($message); // Return the log entity. return $log; } }