public function getInputHtml($value, ElementInterface $element = null): string
    {
        $plugin = Plugin::getInstance();
        $service = $plugin->service;

        // Validate settings
        if (empty($this->source)) {
            return Craft::t('manytomany', 'To use the {pluginName} plugin you need to set a source.',
                ['pluginName' => $plugin->name]);
        }

        if (empty($this->singleField)) {
            return Craft::t('manytomany',
                'To use the {pluginName} plugin you need associate it with a related field.',
                ['pluginName' => $plugin->name]);
        }

        $singleFieldModel = Craft::$app->fields->getFieldById($this->singleField);
        if ($singleFieldModel->getIsTranslatable()) {
            return Craft::t('manytomany',
                'The {pluginName} plugin does not currently work with localized content.',
                ['pluginName' => $plugin->name]);
        }

        // For this iteration of the plugin, everything is a SECTION, but it's setup so it can be
        // refactored in the future to allow for multiple types

        if (!is_object($element) || $element->refHandle() != 'entry') {
            return Craft::t('manytomany',
                'For this version of the {pluginName} plugin, you can only use this field with Entries.',
                ['pluginName' => $plugin->name]);
        }

        /** @var Entry $element */
        $relatedSection = Craft::$app->sections->getSectionById($this->source['value']);

        // Get all the entries that this has already been attached to
        $relatedEntries = $service->getRelatedEntries($element, $relatedSection, $this->singleField);

        // Put related Entries into an array that can be consumed by the JavaScript popup window
        $nonSelectable = [];
        if (!empty($relatedEntries)) {
            foreach ($relatedEntries as $relatedEntry) {
                $nonSelectable[] = $relatedEntry->id;
            }
        }
        $nonSelectable = implode(',', $nonSelectable);

        $id = Craft::$app->view->formatInputId($this->handle);
        $namespacedId = Craft::$app->view->namespaceInputId($id);

        return Craft::$app->view->renderTemplate('manytomany/_input', [
            'name' => $this->handle,
            'value' => $value,
            'id' => $namespacedId,
            'current' => $relatedEntries,
            'section' => $relatedSection->id,
            'nonSelectable' => $nonSelectable,
            'singleField' => $this->singleField,
            'nameSpace' => Craft::$app->view->getNamespace(),
        ]);
    }