Last active
January 25, 2021 22:59
-
-
Save heymarkreeves/71316445304ac7c7b4cb82d3e54fcc0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @link https://clearbold.com | |
*/ | |
namespace temp\temp\fields; | |
use Craft; | |
use craft\base\ElementInterface; | |
use craft\base\Field; | |
use temp\temp\Plugin; | |
/** | |
* Express Forms field | |
* | |
* @author Mark Reeves <###@clearbold.com> | |
* @since 0.2 | |
*/ | |
class ExpressForms extends Field | |
{ | |
// Public Methods | |
// ========================================================================= | |
/** | |
* @inheritdoc | |
*/ | |
public static function displayName(): string | |
{ | |
return Craft::t('temp', 'Express Forms'); | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function getInputHtml($value, ElementInterface $element = null): string | |
{ | |
$name = $this->handle; | |
$id = Craft::$app->getView()->formatInputId($name); | |
$forms = array(); | |
$forms[] = array( | |
'label' => 'None', | |
'value' => 'none' | |
); | |
$tableSchema = Craft::$app->db->schema->getTableSchema('{{%expressforms_forms}}'); | |
if ($tableSchema !== null) { | |
$rows = (new \yii\db\Query()) | |
->select(['name', 'handle']) | |
->from('{{%expressforms_forms}}') | |
->all(); | |
foreach($rows as $row) { | |
$forms[] = array( | |
'label' => $row['name'], | |
'value' => $row['handle'] | |
); | |
} | |
} | |
return '<div class="express-form-field">'. | |
Craft::$app->getView()->renderTemplate('_includes/forms/select', [ | |
'id' => $id, | |
'name' => $name, | |
'value' => $value, | |
'options' => $forms | |
]). | |
'</div>'; | |
} | |
// Private Methods | |
// ========================================================================= | |
/** | |
* @param | |
* | |
* @return mixed | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment