original_string: public static function create_purpose_form($jsonformdata) {
          global $PAGE;
  
          $warnings = [];
  
          $params = external_api::validate_parameters(self::create_purpose_form_parameters(), [
              'jsonformdata' => $jsonformdata
          ]);
  
          // Validate context and access to manage the registry.
          self::validate_context(\context_system::instance());
          api::check_can_manage_data_registry();
  
          $serialiseddata = json_decode($params['jsonformdata']);
          $data = array();
          parse_str($serialiseddata, $data);
  
          $purpose = new \tool_dataprivacy\purpose(0);
          $mform = new \tool_dataprivacy\form\purpose(null, ['persistent' => $purpose], 'post', '', null, true, $data);
  
          $validationerrors = true;
          if ($validateddata = $mform->get_data()) {
              $purpose = api::create_purpose($validateddata);
              $validationerrors = false;
          } else if ($errors = $mform->is_validated()) {
              throw new moodle_exception('generalerror');
          }
  
          $exporter = new purpose_exporter($purpose, ['context' => \context_system::instance()]);
          return [
              'purpose' => $exporter->export($PAGE->get_renderer('core')),
              'validationerrors' => $validationerrors,
              'warnings' => $warnings
          ];
      }
code: public static function create_purpose_form($jsonformdata) {
          global $PAGE;
  
          $warnings = [];
  
          $params = external_api::validate_parameters(self::create_purpose_form_parameters(), [
              'jsonformdata' => $jsonformdata
          ]);
  
          // Validate context and access to manage the registry.
          self::validate_context(\context_system::instance());
          api::check_can_manage_data_registry();
  
          $serialiseddata = json_decode($params['jsonformdata']);
          $data = array();
          parse_str($serialiseddata, $data);
  
          $purpose = new \tool_dataprivacy\purpose(0);
          $mform = new \tool_dataprivacy\form\purpose(null, ['persistent' => $purpose], 'post', '', null, true, $data);
  
          $validationerrors = true;
          if ($validateddata = $mform->get_data()) {
              $purpose = api::create_purpose($validateddata);
              $validationerrors = false;
          } else if ($errors = $mform->is_validated()) {
              throw new moodle_exception('generalerror');
          }
  
          $exporter = new purpose_exporter($purpose, ['context' => \context_system::instance()]);
          return [
              'purpose' => $exporter->export($PAGE->get_renderer('core')),
              'validationerrors' => $validationerrors,
              'warnings' => $warnings
          ];
      }
code_tokens: public static function create_purpose_form ( $ jsonformdata ) { global $ PAGE ; $ warnings = [ ] ; $ params = external_api :: validate_parameters ( self :: create_purpose_form_parameters ( ) , [ 'jsonformdata' => $ jsonformdata ] ) ; // Validate context and access to manage the registry. self :: validate_context ( \ context_system :: instance ( ) ) ; api :: check_can_manage_data_registry ( ) ; $ serialiseddata = json_decode ( $ params [ 'jsonformdata' ] ) ; $ data = array ( ) ; parse_str ( $ serialiseddata , $ data ) ; $ purpose = new \ tool_dataprivacy \ purpose ( 0 ) ; $ mform = new \ tool_dataprivacy \ form \ purpose ( null , [ 'persistent' => $ purpose ] , 'post' , '' , null , true , $ data ) ; $ validationerrors = true ; if ( $ validateddata = $ mform -> get_data ( ) ) { $ purpose = api :: create_purpose ( $ validateddata ) ; $ validationerrors = false ; } else if ( $ errors = $ mform -> is_validated ( ) ) { throw new moodle_exception ( 'generalerror' ) ; } $ exporter = new purpose_exporter ( $ purpose , [ 'context' => \ context_system :: instance ( ) ] ) ; return [ 'purpose' => $ exporter -> export ( $ PAGE -> get_renderer ( 'core' ) ) , 'validationerrors' => $ validationerrors , 'warnings' => $ warnings ] ; }
docstring: Creates a data purpose from form data.
  
  @since Moodle 3.5
  @param string $jsonformdata
  @return array
docstring_tokens: Creates a data purpose from form data .