public function definition() {
        global $PAGE;
        $mform = $this->_form;
        $eventtypes = calendar_get_allowed_event_types();
        if (in_array(true, $eventtypes, true) === false) {
            print_error('nopermissiontoupdatecalendar');
        }

        $mform->addElement('header', 'addsubscriptionform', get_string('importcalendarheading', 'calendar'));

        // Name.
        $mform->addElement('text', 'name', get_string('subscriptionname', 'calendar'), array('maxsize' => '255', 'size' => '40'));
        $mform->addRule('name', get_string('required'), 'required');
        $mform->setType('name', PARAM_TEXT);

        // Import from (url | importfile).
        $mform->addElement('html', get_string('importfrominstructions', 'calendar'));
        $choices = array(CALENDAR_IMPORT_FROM_FILE => get_string('importfromfile', 'calendar'),
            CALENDAR_IMPORT_FROM_URL  => get_string('importfromurl',  'calendar'));
        $mform->addElement('select', 'importfrom', get_string('importcalendarfrom', 'calendar'), $choices);
        $mform->setDefault('importfrom', CALENDAR_IMPORT_FROM_URL);

        // URL.
        $mform->addElement('text', 'url', get_string('importfromurl', 'calendar'), array('maxsize' => '255', 'size' => '50'));
        // Cannot set as PARAM_URL since we need to allow webcal:// protocol.
        $mform->setType('url', PARAM_RAW);
        $mform->setForceLtr('url');

        // Poll interval
        $choices = calendar_get_pollinterval_choices();
        $mform->addElement('select', 'pollinterval', get_string('pollinterval', 'calendar'), $choices);
        $mform->setDefault('pollinterval', 604800);
        $mform->addHelpButton('pollinterval', 'pollinterval', 'calendar');
        $mform->setType('pollinterval', PARAM_INT);

        // Import file
        $mform->addElement('filepicker', 'importfile', get_string('importfromfile', 'calendar'), null, array('accepted_types' => '.ics'));

        // Disable appropriate elements depending on import from value.
        $mform->disabledIf('pollinterval', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE);
        $mform->disabledIf('url',  'importfrom', 'eq', CALENDAR_IMPORT_FROM_FILE);
        $mform->disabledIf('importfile', 'importfrom', 'eq', CALENDAR_IMPORT_FROM_URL);

        // Add the select elements for the available event types.
        $this->add_event_type_elements($mform, $eventtypes);

        // Eventtype: 0 = user, 1 = global, anything else = course ID.
        $mform->addElement('submit', 'add', get_string('add'));

        // Add the javascript required to enhance this mform.
        $PAGE->requires->js_call_amd('core_calendar/event_form', 'init', [$mform->getAttribute('id')]);
    }