@amazeelabs/silverback-campaign-urls 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/drupal/silverback_campaign_urls/.prettierignore +1 -0
  3. package/drupal/silverback_campaign_urls/CHANGELOG.md +82 -0
  4. package/drupal/silverback_campaign_urls/README.md +25 -0
  5. package/drupal/silverback_campaign_urls/composer.json +8 -0
  6. package/drupal/silverback_campaign_urls/config/install/system.action.campaign_url_delete_action.yml +13 -0
  7. package/drupal/silverback_campaign_urls/config/install/views.view.campaign_urls.yml +737 -0
  8. package/drupal/silverback_campaign_urls/graphql/silverback_campaign_urls.base.graphqls +6 -0
  9. package/drupal/silverback_campaign_urls/graphql/silverback_campaign_urls.extension.graphqls +0 -0
  10. package/drupal/silverback_campaign_urls/silverback_campaign_urls.info.yml +10 -0
  11. package/drupal/silverback_campaign_urls/silverback_campaign_urls.links.action.yml +5 -0
  12. package/drupal/silverback_campaign_urls/silverback_campaign_urls.links.menu.yml +12 -0
  13. package/drupal/silverback_campaign_urls/silverback_campaign_urls.permissions.yml +2 -0
  14. package/drupal/silverback_campaign_urls/silverback_campaign_urls.routing.yml +46 -0
  15. package/drupal/silverback_campaign_urls/src/CampaignUrlAccessControlHandler.php +29 -0
  16. package/drupal/silverback_campaign_urls/src/Entity/CampaignUrl.php +179 -0
  17. package/drupal/silverback_campaign_urls/src/Entity/CampaignUrlInterface.php +34 -0
  18. package/drupal/silverback_campaign_urls/src/Entity/CampaignUrlListBuilder.php +38 -0
  19. package/drupal/silverback_campaign_urls/src/Form/CampaignUrlDeleteForm.php +41 -0
  20. package/drupal/silverback_campaign_urls/src/Form/CampaignUrlDeleteMultipleForm.php +145 -0
  21. package/drupal/silverback_campaign_urls/src/Form/CampaignUrlForm.php +45 -0
  22. package/drupal/silverback_campaign_urls/src/Plugin/Action/DeleteCampaignUrl.php +92 -0
  23. package/drupal/silverback_campaign_urls/src/Plugin/GraphQL/SchemaExtension/SilverbackCampaignUrlSchemaExtension.php +28 -0
  24. package/drupal/silverback_campaign_urls/src/Plugin/Validation/Constraint/UniqueCampaignUrlSourceConstraint.php +18 -0
  25. package/drupal/silverback_campaign_urls/src/Plugin/Validation/Constraint/UniqueCampaignUrlSourceConstraintValidator.php +61 -0
  26. package/drupal/silverback_campaign_urls/tests/src/Kernel/CampaignUrlValidationTest.php +57 -0
  27. package/package.json +15 -0
@@ -0,0 +1,6 @@
1
+ type CampaignUrl @entity(type: "campaign_url", bundle: "campaign_url") {
2
+ source: String! @resolveProperty(path: "campaign_url_source.value")
3
+ destination: String! @resolveProperty(path: "campaign_url_destination.value")
4
+ statusCode: Int! @resolveProperty(path: "status_code.value")
5
+ force: Boolean! @resolveProperty(path: "force.value")
6
+ }
@@ -0,0 +1,10 @@
1
+ name: Silverback Campaign Urls
2
+ type: module
3
+ description:
4
+ 'Allows creating campaign url entities that can be afterwards exposed via
5
+ graphql, as redirects.'
6
+ package: Silverback
7
+ core: 8.x
8
+ dependencies:
9
+ - graphql_directives:graphql_directives
10
+ core_version_requirement: ^8 || ^9 || ^10 || ^11
@@ -0,0 +1,5 @@
1
+ campaign_url.add:
2
+ route_name: campaign_url.add
3
+ title: 'Add campaign url'
4
+ appears_on:
5
+ - 'campaign_url.list'
@@ -0,0 +1,12 @@
1
+ campaign_url.list:
2
+ title: 'Campaign URLs'
3
+ parent: system.admin_config_search
4
+ description: 'Administer campaign URLs'
5
+ route_name: campaign_url.list
6
+ menu_name: admin
7
+
8
+ campaign_url.add:
9
+ title: 'Add campaign url'
10
+ parent: campaign_url.list
11
+ route_name: campaign_url.add
12
+ menu_name: admin
@@ -0,0 +1,2 @@
1
+ administer campaign urls:
2
+ title: 'Administer individual campaign URLs'
@@ -0,0 +1,46 @@
1
+ campaign_url.list:
2
+ path: '/admin/config/search/campaign_url'
3
+ defaults:
4
+ _entity_list: 'campaign_url'
5
+ _title: 'Campaign URLs'
6
+ requirements:
7
+ _permission: 'administer campaign urls'
8
+
9
+ entity.campaign_url.canonical:
10
+ path: '/admin/config/search/campaign_url/edit/{campaign_url}'
11
+ defaults:
12
+ _entity_form: 'campaign_url.edit'
13
+ _title: 'Edit campaign URL'
14
+ requirements:
15
+ _entity_access: 'campaign_url.update'
16
+
17
+ campaign_url.add:
18
+ path: '/admin/config/search/campaign_url/add'
19
+ defaults:
20
+ _entity_form: 'campaign_url.default'
21
+ _title: 'Add campaign URL'
22
+ requirements:
23
+ _entity_create_access: 'campaign_url'
24
+
25
+ entity.campaign_url.edit_form:
26
+ path: '/admin/config/search/campaign_url/edit/{campaign_url}'
27
+ defaults:
28
+ _entity_form: 'campaign_url.edit'
29
+ _title: 'Edit campaign URL'
30
+ requirements:
31
+ _entity_access: 'campaign_url.update'
32
+
33
+ entity.campaign_url.delete_form:
34
+ path: '/admin/config/search/campaign_url/delete/{campaign_url}'
35
+ defaults:
36
+ _entity_form: 'campaign_url.delete'
37
+ _title: 'Delete campaign URL'
38
+ requirements:
39
+ _entity_access: 'campaign_url.delete'
40
+
41
+ entity.campaign_url.multiple_delete_confirm:
42
+ path: '/admin/config/search/campaign_url/delete'
43
+ defaults:
44
+ _form: '\Drupal\silverback_campaign_urls\Form\CampaignUrlDeleteMultipleForm'
45
+ requirements:
46
+ _permission: 'administer campaign urls'
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_campaign_urls;
4
+
5
+ use Drupal\Core\Access\AccessResult;
6
+ use Drupal\Core\Entity\EntityAccessControlHandler;
7
+ use Drupal\Core\Entity\EntityInterface;
8
+ use Drupal\Core\Session\AccountInterface;
9
+
10
+ class CampaignUrlAccessControlHandler extends EntityAccessControlHandler {
11
+
12
+ /**
13
+ * {@inheritDoc}
14
+ */
15
+ public function access(EntityInterface $entity, $operation, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
16
+ $account = $this->prepareUser($account);
17
+ if ($operation === 'view label' && !$this->viewLabelOperation) {
18
+ $operation = 'view';
19
+ }
20
+ // Everyone with the "access content" permission should be able to view
21
+ // the campaign URLs (redirects), otherwise they won't be accessible via
22
+ // graphql.
23
+ if ($operation === 'view' && $account->hasPermission('access content')) {
24
+ $result = AccessResult::allowed()->cachePerPermissions();
25
+ return $return_as_object ? $result : $result->isAllowed();
26
+ }
27
+ return parent::access($entity, $operation, $account, TRUE);
28
+ }
29
+ }
@@ -0,0 +1,179 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_campaign_urls\Entity;
4
+
5
+ use Drupal\Core\Entity\ContentEntityBase;
6
+ use Drupal\Core\Entity\EntityChangedTrait;
7
+ use Drupal\Core\Entity\EntityStorageInterface;
8
+ use Drupal\Core\Entity\EntityTypeInterface;
9
+ use Drupal\Core\Field\BaseFieldDefinition;
10
+
11
+ /**
12
+ * The campaign URL entity class.
13
+ *
14
+ * @ContentEntityType(
15
+ * id = "campaign_url",
16
+ * label = @Translation("Campaign URL"),
17
+ * handlers = {
18
+ * "list_builder" = "Drupal\silverback_campaign_urls\Entity\CampaignUrlListBuilder",
19
+ * "access" = "Drupal\silverback_campaign_urls\CampaignUrlAccessControlHandler",
20
+ * "form" = {
21
+ * "default" = "Drupal\silverback_campaign_urls\Form\CampaignUrlForm",
22
+ * "delete" = "Drupal\silverback_campaign_urls\Form\CampaignUrlDeleteForm",
23
+ * "edit" = "Drupal\silverback_campaign_urls\Form\CampaignUrlForm"
24
+ * },
25
+ * "views_data" = "Drupal\views\EntityViewsData"
26
+ * },
27
+ * base_table = "campaign_url",
28
+ * translatable = FALSE,
29
+ * admin_permission = "administer campaign urls",
30
+ * entity_keys = {
31
+ * "id" = "cid",
32
+ * "label" = "campaign_url_source",
33
+ * "uuid" = "uuid",
34
+ * "bundle" = "type",
35
+ * },
36
+ * links = {
37
+ * "canonical" = "/admin/config/search/campaign_url/edit/{campaign_url}",
38
+ * "delete-form" = "/admin/config/search/campaign_url/delete/{campaign_url}",
39
+ * "edit-form" = "/admin/config/search/campaign_url/edit/{campaign_url}",
40
+ * },
41
+ * constraints = {
42
+ * "UniqueCampaignUrlSource" = {}
43
+ * }
44
+ * )
45
+ */
46
+ class CampaignUrl extends ContentEntityBase implements CampaignUrlInterface {
47
+ use EntityChangedTrait;
48
+
49
+ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
50
+ $fields = parent::baseFieldDefinitions($entity_type);
51
+
52
+ $fields['campaign_url_source'] = BaseFieldDefinition::create('string')
53
+ ->setLabel(t('Source'))
54
+ ->setDescription(t('Please provide the source path for this campaign URL. You can enter an internal path (starting with "/") or an external URL such as https://example.com. However, it can be any arbitrary source path that your hosting provider understands.'))
55
+ ->setRequired(TRUE)
56
+ ->setSetting('max_length', 1024)
57
+ ->setDisplayOptions('form', [
58
+ 'type' => 'string_textfield',
59
+ 'weight' => -5,
60
+ ])
61
+ ->setDisplayConfigurable('form', TRUE);
62
+
63
+ $fields['campaign_url_destination'] = BaseFieldDefinition::create('string')
64
+ ->setLabel(t('Destination'))
65
+ ->setDescription(t('Same as <em>Source</em>, you can enter an internal path (starting with "/") or an external URL such as https://example.com. However, it can be any destination path that your hosting provider understands. If the site is multilingual, the language parameter has to be in the path (e.g.: <em>/en/test</em>)'))
66
+ ->setRequired(TRUE)
67
+ ->setSetting('max_length', 1024)
68
+ ->setDisplayOptions('form', [
69
+ 'type' => 'string_textfield',
70
+ 'weight' => -3,
71
+ ])
72
+ ->setDisplayConfigurable('form', TRUE);
73
+
74
+ $fields['status_code'] = BaseFieldDefinition::create('integer')
75
+ ->setLabel(t('Status code'))
76
+ ->setDescription(t('The campaign url redirect status code.'))
77
+ ->setDefaultValue(301);
78
+
79
+ $fields['force'] = BaseFieldDefinition::create('boolean')
80
+ ->setLabel(t('Force redirect'))
81
+ ->setDescription(t('Force the redirect, even if there is already a static file matching the source URL.'))
82
+ ->setDefaultValue(TRUE)
83
+ ->setDisplayOptions('form', [
84
+ 'type' => 'boolean_checkbox',
85
+ 'settings' => [
86
+ 'display_label' => TRUE,
87
+ ],
88
+ ])
89
+ ->setDisplayConfigurable('form', TRUE);
90
+
91
+ $fields['author'] = BaseFieldDefinition::create('entity_reference')
92
+ ->setLabel(t('Author'))
93
+ ->setDescription(t('The user ID of the campaign URl author.'))
94
+ ->setDefaultValueCallback('\Drupal\silverback_campaign_urls\Entity\CampaignUrl::getCurrentUserId')
95
+ ->setSettings(array(
96
+ 'target_type' => 'user',
97
+ ));
98
+ $fields['edited_by'] = BaseFieldDefinition::create('entity_reference')
99
+ ->setLabel(t('Edited by'))
100
+ ->setDescription(t('The user ID of the last person who edited the campaign URL.'))
101
+ ->setDefaultValueCallback('\Drupal\silverback_campaign_urls\Entity\CampaignUrl::getCurrentUserId')
102
+ ->setSettings(array(
103
+ 'target_type' => 'user',
104
+ ));
105
+
106
+ $fields['created'] = BaseFieldDefinition::create('created')
107
+ ->setLabel(t('Created'))
108
+ ->setDescription(t('The date when the campaign URL was created.'));
109
+ $fields['changed'] = BaseFieldDefinition::create('changed')
110
+ ->setLabel(t('Updated'))
111
+ ->setDescription(t('The date when the campaign URL was last updated.'));
112
+ return $fields;
113
+ }
114
+
115
+ /**
116
+ * {@inheritdoc}
117
+ */
118
+ public static function preCreate(EntityStorageInterface $storage, array &$values) {
119
+ $values += [
120
+ 'type' => 'campaign_url',
121
+ ];
122
+ }
123
+
124
+ /**
125
+ * {@inheritDoc}
126
+ */
127
+ public function preSave(EntityStorageInterface $storage) {
128
+ parent::preSave($storage);
129
+ // On every save, update the value of the editey_by field with the current
130
+ // user's ID.
131
+ $this->set('edited_by', static::getCurrentUserId());
132
+ }
133
+
134
+ /**
135
+ * {@inheritDoc}
136
+ */
137
+ public function getStatusCode() {
138
+ if ($this->get('status_code')->isEmpty()) {
139
+ return NULL;
140
+ }
141
+ return $this->get('status_code')->getValue()[0]['value'];
142
+ }
143
+
144
+ /**
145
+ * {@inheritDoc}
146
+ */
147
+ public function isCampaignRedirectForced() {
148
+ if ($this->get('force')->isEmpty()) {
149
+ return FALSE;
150
+ }
151
+ return (int) $this->get('force')->getValue()[0]['value'] > 0;
152
+ }
153
+
154
+ /**
155
+ * {@inheritDoc}
156
+ */
157
+ public function getSource() {
158
+ return $this->get('campaign_url_source')->getValue()[0]['value'];
159
+ }
160
+
161
+ /**
162
+ * {@inheritDoc}
163
+ */
164
+ public function getDestination() {
165
+ return $this->get('campaign_url_destination')->getValue()[0]['value'];
166
+ }
167
+
168
+ /**
169
+ * Default value callback for the author and the edite_by fields.
170
+ *
171
+ * @see ::baseFieldDefinitions()
172
+ *
173
+ * @return array
174
+ * An array containing the current user id.
175
+ */
176
+ public static function getCurrentUserId() {
177
+ return array(\Drupal::currentUser()->id());
178
+ }
179
+ }
@@ -0,0 +1,34 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_campaign_urls\Entity;
4
+
5
+ use Drupal\Core\Entity\EntityChangedInterface;
6
+
7
+ interface CampaignUrlInterface extends EntityChangedInterface {
8
+
9
+ /**
10
+ * Returns the status code of the campaign URL.
11
+ *
12
+ * @return int
13
+ */
14
+ public function getStatusCode();
15
+
16
+ /**
17
+ * Returns true of the campaign URL redirect is forced, false otherwise.
18
+ *
19
+ * @return boolean
20
+ */
21
+ public function isCampaignRedirectForced();
22
+
23
+ /**
24
+ * Returns the source of the campaign URL.
25
+ * @return string
26
+ */
27
+ public function getSource();
28
+
29
+ /**
30
+ * Returns the destination of the campaign URL.
31
+ * @return string
32
+ */
33
+ public function getDestination();
34
+ }
@@ -0,0 +1,38 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_campaign_urls\Entity;
4
+
5
+ use Drupal\Core\Entity\EntityInterface;
6
+ use Drupal\Core\Entity\EntityListBuilder;
7
+
8
+ class CampaignUrlListBuilder extends EntityListBuilder {
9
+
10
+ /**
11
+ * {@inheritdoc}
12
+ */
13
+ public function buildHeader() {
14
+ $header['source'] = $this->t('Source');
15
+ $header['destination'] = $this->t('Destination');
16
+ $header['status_code'] = $this->t('Status code');
17
+ $header['force'] = $this->t('Force redirect');
18
+
19
+ return $header + parent::buildHeader();
20
+ }
21
+
22
+
23
+ /**
24
+ * {@inheritdoc}
25
+ */
26
+ public function buildRow(EntityInterface $entity) {
27
+ if (!$entity instanceof CampaignUrl) {
28
+ return parent::buildRow($entity);
29
+ }
30
+ $row['source'] = $entity->getSource();
31
+ $row['destination'] = $entity->getDestination();
32
+ $row['status_code'] = $entity->getStatusCode();
33
+ $row['force'] = $entity->isCampaignRedirectForced() ? $this->t('Yes') : $this->t('No');
34
+
35
+ return $row + parent::buildRow($entity);
36
+ }
37
+
38
+ }
@@ -0,0 +1,41 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_campaign_urls\Form;
4
+
5
+ use Drupal\Core\Entity\ContentEntityConfirmFormBase;
6
+ use Drupal\Core\Url;
7
+ use Drupal\Core\Form\FormStateInterface;
8
+
9
+ class CampaignUrlDeleteForm extends ContentEntityConfirmFormBase {
10
+
11
+ /**
12
+ * {@inheritdoc}
13
+ */
14
+ public function getQuestion() {
15
+ return $this->t('Are you sure you want to delete the campaign URL %source', array('%source' => $this->entity->getSource()));
16
+ }
17
+
18
+ /**
19
+ * {@inheritdoc}
20
+ */
21
+ public function getCancelUrl() {
22
+ return new Url('campaign_url.list');
23
+ }
24
+
25
+ /**
26
+ * {@inheritdoc}
27
+ */
28
+ public function getConfirmText() {
29
+ return $this->t('Delete');
30
+ }
31
+
32
+ /**
33
+ * {@inheritdoc}
34
+ */
35
+ public function submitForm(array &$form, FormStateInterface $form_state) {
36
+ $this->entity->delete();
37
+ $this->messenger()->addMessage(t('The campaign URL %source has been deleted.', array('%source' => $this->entity->getSource())));
38
+ $form_state->setRedirect('campaign_url.list');
39
+ }
40
+
41
+ }
@@ -0,0 +1,145 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_campaign_urls\Form;
4
+
5
+ use Drupal\Core\Entity\EntityTypeManagerInterface;
6
+ use Drupal\Core\Form\ConfirmFormBase;
7
+ use Drupal\Core\Form\FormStateInterface;
8
+ use Drupal\Core\Url;
9
+ use Drupal\Core\TempStore\PrivateTempStoreFactory;
10
+ use Symfony\Component\DependencyInjection\ContainerInterface;
11
+ use Symfony\Component\HttpFoundation\RedirectResponse;
12
+ use Drupal\Core\Session\AccountInterface;
13
+ use Drupal\Core\StringTranslation\TranslationInterface;
14
+
15
+ /**
16
+ * Provides a campaign URL deletion confirmation form.
17
+ */
18
+ class CampaignUrlDeleteMultipleForm extends ConfirmFormBase {
19
+
20
+ /**
21
+ * The array of campaign URLs to delete.
22
+ *
23
+ * @var string[][]
24
+ */
25
+ protected $campaignURLs = [];
26
+
27
+ /**
28
+ * The private tempstore factory.
29
+ *
30
+ * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
31
+ */
32
+ protected $privateTempStoreFactory;
33
+
34
+ /**
35
+ * The campaign URL storage.
36
+ *
37
+ * @var \Drupal\Core\Entity\EntityStorageInterface
38
+ */
39
+ protected $campaignUrlStorage;
40
+
41
+ /**
42
+ * The current user.
43
+ *
44
+ * @var \Drupal\Core\Session\AccountInterface
45
+ */
46
+ protected $currentUser;
47
+
48
+ /**
49
+ * Constructs a CampaignUrlDeleteMultipleForm object.
50
+ *
51
+ * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
52
+ * The tempstore factory.
53
+ * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
54
+ * The entity type manager.
55
+ * @param \Drupal\Core\Session\AccountInterface $account
56
+ * The current user.
57
+ * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
58
+ * The String translation.
59
+ */
60
+ public function __construct(
61
+ PrivateTempStoreFactory $temp_store_factory,
62
+ EntityTypeManagerInterface $entity_type_manager,
63
+ AccountInterface $account,
64
+ TranslationInterface $string_translation
65
+ ) {
66
+ $this->privateTempStoreFactory = $temp_store_factory;
67
+ $this->campaignUrlStorage = $entity_type_manager->getStorage('campaign_url');
68
+ $this->currentUser = $account;
69
+ $this->setStringTranslation($string_translation);
70
+ }
71
+
72
+ /**
73
+ * {@inheritdoc}
74
+ */
75
+ public static function create(ContainerInterface $container) {
76
+ return new static(
77
+ $container->get('tempstore.private'),
78
+ $container->get('entity_type.manager'),
79
+ $container->get('current_user'),
80
+ $container->get('string_translation')
81
+ );
82
+ }
83
+
84
+ /**
85
+ * {@inheritdoc}
86
+ */
87
+ public function getFormId() {
88
+ return 'campaign_url_multiple_delete_confirm';
89
+ }
90
+
91
+ /**
92
+ * {@inheritdoc}
93
+ */
94
+ public function getQuestion() {
95
+ return $this->formatPlural(count($this->campaignURLs), 'Are you sure you want to delete this campaign URL?', 'Are you sure you want to delete these campaign URLs?');
96
+ }
97
+
98
+ /**
99
+ * {@inheritdoc}
100
+ */
101
+ public function getCancelUrl() {
102
+ return new Url('campaign_url.list');
103
+ }
104
+
105
+ /**
106
+ * {@inheritdoc}
107
+ */
108
+ public function getConfirmText() {
109
+ return $this->t('Delete');
110
+ }
111
+
112
+ /**
113
+ * {@inheritdoc}
114
+ */
115
+ public function buildForm(array $form, FormStateInterface $form_state) {
116
+ $this->campaignURLs = $this->privateTempStoreFactory->get('campaign_url_multiple_delete_confirm')->get($this->currentUser->id());
117
+ if (empty($this->campaignURLs)) {
118
+ return new RedirectResponse($this->getCancelUrl()->setAbsolute()->toString());
119
+ }
120
+
121
+ $form['campaign_urls'] = [
122
+ '#theme' => 'item_list',
123
+ '#items' => array_map(function ($campaignURL) {
124
+ return $campaignURL->label();
125
+ }, $this->campaignURLs),
126
+ ];
127
+ return parent::buildForm($form, $form_state);
128
+ }
129
+
130
+ /**
131
+ * {@inheritdoc}
132
+ */
133
+ public function submitForm(array &$form, FormStateInterface $form_state) {
134
+
135
+ if ($form_state->getValue('confirm') && !empty($this->campaignURLs)) {
136
+ $this->campaignUrlStorage->delete($this->campaignURLs);
137
+ $this->privateTempStoreFactory->get('campaign_url_multiple_delete_confirm')->delete($this->currentUser->id());
138
+ $count = count($this->campaignURLs);
139
+ $this->logger('campaign_url')->notice('Deleted @count campaign URLs.', ['@count' => $count]);
140
+ $this->messenger()->addMessage($this->stringTranslation->formatPlural($count, 'Deleted 1 campaign URL.', 'Deleted @count campaign URLs.'));
141
+ }
142
+ $form_state->setRedirect('campaign_url.list');
143
+ }
144
+
145
+ }
@@ -0,0 +1,45 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_campaign_urls\Form;
4
+
5
+ use Drupal\Core\Entity\ContentEntityForm;
6
+ use Drupal\Core\Form\FormStateInterface;
7
+
8
+ class CampaignUrlForm extends ContentEntityForm {
9
+
10
+ /**
11
+ * {@inheritdoc}
12
+ */
13
+ public function save(array $form, FormStateInterface $form_state) {
14
+ parent::save($form, $form_state);
15
+ $this->messenger()->addMessage(t('The campaign URL has been saved.'));
16
+ $form_state->setRedirect('campaign_url.list');
17
+ }
18
+
19
+ /**
20
+ * {@inheritDoc}
21
+ */
22
+ public function form(array $form, FormStateInterface $form_state) {
23
+ $form = parent::form($form, $form_state);
24
+ /** @var \Drupal\silverback_campaign_urls\Entity\CampaignUrl $campaignUrl */
25
+ $campaignUrl = $this->entity;
26
+ $defaultCode = $campaignUrl->getStatusCode() ? $campaignUrl->getStatusCode() : 301;
27
+ $form['status_code'] = [
28
+ '#type' => 'select',
29
+ '#title' => $this->t('Redirect status'),
30
+ '#description' => $this->t('You can find more information about HTTP redirect status codes at <a href="@status-codes" target="_blank">@status-codes</a>. Additionally, some hosting providers, like Netlify, support also URL rewrites, which means you can assign a 200 status code to redirect rules. Here is some <a href="@rewrite-docs" target="_blank">more documentation</a>.', ['@status-codes' => 'http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection', '@rewrite-docs' => 'https://docs.netlify.com/routing/redirects/rewrites-proxies']),
31
+ '#default_value' => $defaultCode,
32
+ '#options' => [
33
+ 200 => t('200 Rewrite'),
34
+ 300 => t('300 Multiple Choices'),
35
+ 301 => t('301 Moved Permanently'),
36
+ 302 => t('302 Found'),
37
+ 303 => t('303 See Other'),
38
+ 304 => t('304 Not Modified'),
39
+ 305 => t('305 Use Proxy'),
40
+ 307 => t('307 Temporary Redirect'),
41
+ ]
42
+ ];
43
+ return $form;
44
+ }
45
+ }