NewRelicRpmDeploy.php in New Relic 8
File
src/Form/NewRelicRpmDeploy.php
View source
<?php
namespace Drupal\new_relic_rpm\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormBase;
use Drupal\new_relic_rpm\Client\NewRelicApiClient;
use Symfony\Component\DependencyInjection\ContainerInterface;
class NewRelicRpmDeploy extends FormBase {
protected $newRelicClient;
public function __construct(NewRelicApiClient $new_relic_client) {
$this->newRelicClient = $new_relic_client;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('new_relic_rpm.client'));
}
public function getFormId() {
return 'new_relic_rpm_deploy';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = [];
$form['revision'] = [
'#type' => 'textfield',
'#title' => $this
->t('Revision'),
'#required' => TRUE,
'#description' => $this
->t('Add a revision number to this deployment.'),
];
$form['description'] = [
'#type' => 'textarea',
'#title' => $this
->t('Description'),
'#description' => $this
->t('Provide some notes and description regarding this deployment.'),
];
$form['user'] = [
'#type' => 'textfield',
'#title' => $this
->t('User'),
'#default_value' => $this
->currentUser()
->getAccountName(),
'#description' => $this
->t('Enter the name for this deployment of your application. This will be the name shown in your list of deployments on the New Relic website.'),
];
$form['changelog'] = [
'#type' => 'textarea',
'#title' => $this
->t('Changelog'),
'#description' => $this
->t('Provide a specific changelog for this deployment.'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Create Deployment'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$deployment = $this->newRelicClient
->createDeployment($form_state
->getValue([
'revision',
]), $form_state
->getValue([
'description',
]), $form_state
->getValue([
'user',
]), $form_state
->getValue([
'changelog',
]));
if ($deployment) {
$this
->messenger()
->addStatus($this
->t('New Relic deployment created successfully.'));
}
else {
$this
->messenger()
->addError($this
->t('New Relic deployment failed.'));
}
}
}
Classes
Name |
Description |
NewRelicRpmDeploy |
Provides a form to allow marking deployments on the New Relic interface. |