Browse Source

Add files via upload

master
Everton Kennedy 9 years ago committed by GitHub
parent
commit
20ed3c8ca4
  1. 10
      amars_conditional_fields.info.yml
  2. 151
      amars_conditional_fields.module
  3. 6
      amars_conditional_fields.routing.yml
  4. 14
      composer.json
  5. 19
      src/Controller/RoblibController.php
  6. 1
      templates/amars_conditional_fields.html.twig

10
amars_conditional_fields.info.yml

@ -0,0 +1,10 @@
name: AMARS Conditional Fields
description: 'Custom Roblib module using API #states to set conditions on sighting report form fields for the AMARS project.'
package: Roblib
type: module
core: 8.x
#configure: amars_conditional_fields.list
dependencies:
- system (>=8.2.0)

151
amars_conditional_fields.module

@ -0,0 +1,151 @@
<?php
/**
* @file
* Custom Roblib module using API #states to set conditions on sighting report form fields for the AMARS project.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function amars_conditional_fields_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the amars_conditional_fields module.
case 'help.page.amars_conditional_fields':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('AMARS Conditional Fields module.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function amars_conditional_fields_theme() {
return [
'amars_conditional_fields' => [
'render element' => 'children',
],
];
}
/**
* Implements hook_form_alter().
*
* On fox_sighting_report node add and edit, set conditional fields using API #states based on values of
* other form fields.
*/
function amars_conditional_fields_form_node_fox_sighting_report_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['field_report_frequency_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_frequency"]' => ['value' => 'Other (please specify below)']
]
];
$form['field_report_count_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_count"]' => ['value' => '4 or more']
]
];
$form['field_report_age_2']['widget']['#states'] = [
'visible' => [
[':input[name="field_report_count"]' => ['value' => (string) '2']],
[':input[name="field_report_count"]' => ['value' => (string) '3']],
[':input[name="field_report_count"]' => ['value' => (string) '4 or more']],
]
];
$form['field_report_age_3']['widget']['#states'] = [
'visible' => [
[':input[name="field_report_count"]' => ['value' => (string) '3']],
[':input[name="field_report_count"]' => ['value' => (string) '4 or more']],
]
];
$form['field_report_age_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_count"]' => ['value' => '4 or more']
]
];
$form['field_fox_report_colour_2']['widget']['#states'] = [
'visible' => [
[':input[name="field_report_count"]' => ['value' => (string) '2']],
[':input[name="field_report_count"]' => ['value' => (string) '3']],
[':input[name="field_report_count"]' => ['value' => (string) '4 or more']],
]
];
$form['field_fox_report_colour_3']['widget']['#states'] = [
'visible' => [
[':input[name="field_report_count"]' => ['value' => (string) '3']],
[':input[name="field_report_count"]' => ['value' => (string) '4 or more']],
]
];
$form['field_fox_report_colour_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_count"]' => ['value' => '4 or more']
]
];
$form['field_report_weather_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_weather"]' => ['value' => 'Other (please specify below)']
]
];
return $form;
}
/**
* Implements hook_form_alter().
*
* On coyote_sighting_report node add and edit, set conditional fields using API #states based on values of
* other form fields.
*/
function amars_conditional_fields_form_node_coyote_sighting_report_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['field_report_count_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_count"]' => ['value' => '4 or more']
]
];
return $form;
}
/**
* Implements hook_form_alter().
*
* On wildlife_sighting_report node add and edit, set conditional fields using API #states based on values of
* other form fields.
*/
function amars_conditional_fields_form_node_wildlife_sighting_report_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['field_report_feeder_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_feeder[Other (please specify below)]"]' => ['checked' => TRUE]
]
];
$form['field_report_feeder_animals_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_feeder_animals[Other (please specify below)]"]' => ['checked' => TRUE]
]
];
$form['field_report_animal_acts_more']['widget'][0]['value']['#states'] = [
'visible' => [
':input[name="field_report_animal_acts[Other (please specify below)]"]' => ['checked' => TRUE]
]
];
return $form;
}

6
amars_conditional_fields.routing.yml

@ -0,0 +1,6 @@
amars_conditional_fields:
path: /roblib/{count}
defaults:
_controller: Drupal\amars_conditional_fields\Controller\RoblibController::roblib
requirements:
_permission: access content

14
composer.json

@ -0,0 +1,14 @@
{
"name": "roblib/amars_conditional_fields",
"type": "drupal-custom-module",
"description": "Custom Roblib module using API #states to set conditions on sighting report form fields for the AMARS project.",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "",
"minimum-stability": "dev",
"support": {
"issues": "",
"source": ""
},
"require": { }
}

19
src/Controller/RoblibController.php

@ -0,0 +1,19 @@
<?php
namespace Drupal\amars_conditional_fields\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* Created by PhpStorm.
* User: ekennedy
* Date: 2017-03-10
* Time: 12:41 PM
*/
class RoblibController {
public function roblib($count) {
return new Response();
}
}

1
templates/amars_conditional_fields.html.twig

@ -0,0 +1 @@
<!-- Add you custom twig html here -->
Loading…
Cancel
Save