Skip to content

Instantly share code, notes, and snippets.

@heymarkreeves
Last active January 25, 2021 22:59
Show Gist options
  • Save heymarkreeves/71316445304ac7c7b4cb82d3e54fcc0a to your computer and use it in GitHub Desktop.
Save heymarkreeves/71316445304ac7c7b4cb82d3e54fcc0a to your computer and use it in GitHub Desktop.
<?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