public static function add_entry($glossaryid, $concept, $definition, $definitionformat, $options = array()) {
        global $CFG;

        $params = self::validate_parameters(self::add_entry_parameters(), array(
            'glossaryid' => $glossaryid,
            'concept' => $concept,
            'definition' => $definition,
            'definitionformat' => $definitionformat,
            'options' => $options,
        ));
        $warnings = array();

        // Get and validate the glossary.
        list($glossary, $context, $course, $cm) = self::validate_glossary($params['glossaryid']);
        require_capability('mod/glossary:write', $context);

        if (!$glossary->allowduplicatedentries) {
            if (glossary_concept_exists($glossary, $params['concept'])) {
                throw new moodle_exception('errconceptalreadyexists', 'glossary');
            }
        }

        // Prepare the entry object.
        $entry = new stdClass;
        $entry->id = null;
        $entry->aliases = '';
        $entry->usedynalink = $CFG->glossary_linkentries;
        $entry->casesensitive = $CFG->glossary_casesensitive;
        $entry->fullmatch = $CFG->glossary_fullmatch;
        $entry->concept = $params['concept'];
        $entry->definition_editor = array(
            'text' => $params['definition'],
            'format' => $params['definitionformat'],
        );
        // Options.
        foreach ($params['options'] as $option) {
            $name = trim($option['name']);
            switch ($name) {
                case 'inlineattachmentsid':
                    $entry->definition_editor['itemid'] = clean_param($option['value'], PARAM_INT);
                    break;
                case 'attachmentsid':
                    $entry->attachment_filemanager = clean_param($option['value'], PARAM_INT);
                    break;
                case 'categories':
                    $entry->categories = clean_param($option['value'], PARAM_SEQUENCE);
                    $entry->categories = explode(',', $entry->categories);
                    break;
                case 'aliases':
                    $entry->aliases = clean_param($option['value'], PARAM_NOTAGS);
                    // Convert to the expected format.
                    $entry->aliases = str_replace(",", "\n", $entry->aliases);
                    break;
                case 'usedynalink':
                case 'casesensitive':
                case 'fullmatch':
                    // Only allow if linking is enabled.
                    if ($glossary->usedynalink) {
                        $entry->{$name} = clean_param($option['value'], PARAM_BOOL);
                    }
                    break;
                default:
                    throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
            }
        }

        $entry = glossary_edit_entry($entry, $course, $cm, $glossary, $context);

        return array(
            'entryid' => $entry->id,
            'warnings' => $warnings
        );
    }