Skip to content

Commit

Permalink
Merge pull request #12 from wfp/develop
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
lashab committed May 13, 2016
2 parents 9115c2e + 0e710e1 commit 33c5b35
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 49 deletions.
86 changes: 48 additions & 38 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Controller/SurveyListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function surveyListPage() {
], [
'attributes' => [
'class' => $button_class,
]
],
])),
$this->l(t('Add HTML survey'), Url::fromRoute($route, [
'plugin_id' => 'survey-html',
], [
'attributes' => [
'class' => $button_class,
]
],
])),
],
'attributes' => ['class' => 'action-links'],
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin/Block/SurveyEmbedCodeBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function blockForm($form, FormStateInterface $form_state) {
$manage_survay_default_value = $this->configuration['manage_survey'];
}

$form['#attributes'] = ['class' => ['block-survey-form']];

$form['manage_survey_embed'] = [
'#type' => 'url',
'#title' => $this->t('Manage survey embed'),
Expand Down
7 changes: 5 additions & 2 deletions src/Plugin/Block/SurveyHtmlBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Xss;

/**
* Provides a 'Survey html' block.
Expand All @@ -34,7 +35,7 @@ public function blockForm($form, FormStateInterface $form_state) {
'#title' => $this->t('Manage survey'),
'#description' => $this->t('Optional URL to third party survey tool.'),
'#default_value' => $manage_survey_default_value,
'#weight'=> 20,
'#weight' => 20,
];

$html_default_value = '';
Expand All @@ -50,6 +51,8 @@ public function blockForm($form, FormStateInterface $form_state) {
'#weight' => 10,
];

$form['#attributes'] = ['class' => ['block-survey-form']];

return $form;
}

Expand All @@ -68,7 +71,7 @@ public function build() {
*/
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['manage_survey'] = $form_state->getValue('manage_survey');
$this->configuration['html'] = $form_state->getValue('html');
$this->configuration['html'] = Xss::filter($form_state->getValue('html'));
}

}
34 changes: 27 additions & 7 deletions survey_manager.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\block\Entity\Block;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;

/**
* Implements hook_help().
Expand Down Expand Up @@ -51,14 +52,33 @@ function _survey_manager_get_surveys($survey_plugin_id) {
* Implements hook_form_alter().
*/
function survey_manager_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == "block_admin_display_form") {
foreach ($form['blocks'] as $key => $block) {
if (!empty($block['operations']['#links']['edit']['url'])) {
$block_plugin_id = $block['operations']['#links']['edit']['url']->getOptions()['entity']->getPluginId();
if ($block_plugin_id == 'survey_embed_code_block') {
unset($form['blocks'][$key]);
switch ($form_id) {
case 'block_form':
if ($form['settings']['#attributes']['class'][0] == 'block-survey-form') {
$form['actions']['submit']['#submit'][] = 'survey_manager_block_submit_callback';
}
break;

case 'block_admin_display_form':
foreach ($form['blocks'] as $key => $block) {
if (!empty($block['operations']['#links']['edit']['url'])) {
$block_plugin_id = $block['operations']['#links']['edit']['url']->getOptions()['entity']->getPluginId();
if ($block_plugin_id == 'survey_embed_code_block') {
unset($form['blocks'][$key]);
}
}
}
}
break;
}
}

/**
* Custom block submit callback.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* Redirects to the survey list page.
*/
function survey_manager_block_submit_callback() {
$response = new RedirectResponse(\Drupal::url('survey_manager.survey_list_controller_index'));
return $response->send();
}

0 comments on commit 33c5b35

Please sign in to comment.