Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Drupalrecipe_searchForm;
- use DrupalCoreFormFormStateInterface;
- use DrupalCoreFormConfirmFormBase;
- use DrupalCoreUrl;
- /**
- * Class DeleteIngredient
- *
- * @package Drupalrecipe_searchForm
- */
- class DeleteIngredient extends ConfirmFormBase{
- /**
- * {@inheritdoc}
- */
- public function getFormId() {
- return 'delete_ingredient';
- }
- public $cid;
- public function getQuestion() {
- return t('Do you want to delete %cid?', array('%cid' => $this->cid));
- }
- public function getCancelUrl() {
- return new Url('recipe_search.recipes');
- }
- public function getDescription() {
- return t('Only do this if you are sure!');
- }
- /**
- * {@inheritdoc}
- */
- public function getConfirmText() {
- return t('Delete it!');
- }
- /**
- * {@inheritdoc}
- */
- public function getCancelText() {
- return t('Cancel');
- }
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state, $cid = NULL) {
- $this->pid = $cid;
- return parent::buildForm($form, $form_state);
- }
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $database = Drupal::database();
- $database->delete('ingredient_list')
- ->condition('pid', $this->pid)
- ->execute();
- $form_state->setRedirect('recipe_search.recipes');
- }
- <?php
- namespace Drupalrecipe_searchForm;
- use DrupalCoreFormFormBase;
- use DrupalCoreFormFormStateInterface;
- /**
- * Class DeleteIngredient
- *
- * @package Drupalrecipe_searchForm
- */
- class DeleteIngredient extends FormBase{
- /**
- * {@inheritdoc}
- */
- public function getFormId() {
- return 'delete_ingredient';
- }
- public $cid;
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state, $cid = NULL) {
- $this->pid = $cid;
- return parent::buildForm($form, $form_state);
- }
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $database = Drupal::database();
- $database->delete('ingredient_list')
- ->condition('pid', $this->pid)
- ->execute();
- $form_state->setRedirect('recipe_search.recipes');
- }
- }
- //FETCH THE INGREDIENTS TO MAKE AN API CALL
- $result = $connection->select('ingredient_list', 'il');
- $result->fields('il', array('ingredient', 'pid'));
- $result->condition('uid', $uid);
- $data = $result->execute();
- $results = $data->fetchAll(PDO::FETCH_OBJ);
- foreach ($results as $field) {
- $delete = Url::fromUserInput('/delete/'.$field->pid);
- array_push($ingredients, ["ingredient" => $field->ingredient, "delete" => $delete]);
- array_push($ingredientsArray, $field->ingredient);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement