Skip to content

Commit

Permalink
Show custom field for email
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 12, 2024
1 parent 2820af1 commit 018e1e4
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 23 deletions.
1 change: 0 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
add layout in controller if added
custom field date types
custom field email
custom field gender
multi relations in controller, model
pagination template if bootstrap
12 changes: 12 additions & 0 deletions src/Colfield.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ public function withClass($class)

return $this;
}

/**
* @param string $name
*
* @return self
*/
public function withName($name)
{
$this->name = $name;

return $this;
}
}
12 changes: 0 additions & 12 deletions src/Template/Fields/BooleanField.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,4 @@ public function getPlate()

return $lines;
}

/**
* @param string $name
*
* @return self
*/
public function withName($name)
{
$this->name = $name;

return $this;
}
}
36 changes: 36 additions & 0 deletions src/Template/Fields/EmailField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Rougin\Combustor\Template\Fields;

use Rougin\Combustor\Colfield;

/**
* @package Combustor
*
* @author Rougin Gutib <[email protected]>
*/
class EmailField extends Colfield
{
/**
* @return string[]
*/
public function getPlate()
{
$class = $this->class;

$field = $this->accessor;

$name = $this->getName();

$html = '<?= form_input([\'type\' => \'email\', \'name\' => \'' . $name . '\', \'value\' => set_value(\'' . $name . '\')]) ?>';

if ($this->edit)
{
$html = str_replace('set_value(\'' . $name . '\')', 'set_value(\'' . $name . '\', ' . $field . ')', $html);
}

$html = str_replace(')]) ?>', '), \'class\' => \'' . $class . '\']) ?>', $html);

return array($html);
}
}
13 changes: 11 additions & 2 deletions src/Template/FormPlate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Rougin\Combustor\Inflector;
use Rougin\Combustor\Template\Fields\BooleanField;
use Rougin\Combustor\Template\Fields\DefaultField;
use Rougin\Combustor\Template\Fields\EmailField;
use Rougin\Describe\Column;

/**
Expand Down Expand Up @@ -142,15 +143,17 @@ public function make($tab = '')

$result = implode("\n", $lines);

// Replace all empty class placeholders -------------
// Replace all empty class placeholders ------------------
$result = str_replace(' class=""', '', $result);

$result = str_replace(', \'class\' => \'\'', '', $result);

$result = str_replace(', \'class=""\'', '', $result);

$search = ', \'\', [\'class\' => \'\']';

return str_replace($search, '', $result);
// --------------------------------------------------
// -------------------------------------------------------
}

/**
Expand Down Expand Up @@ -205,6 +208,12 @@ protected function getField(Column $column, $tab = '')
$name = $this->getAccessor($column);

$field = new DefaultField($this->edit, $tab);

if ($column->getField() === 'email')
{
$field = new EmailField($this->edit, $tab);
}

$field->withName($column->getField());

$class = $this->bootstrap ? 'form-control' : '';
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Doctrine/Common/CreateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?= form_open('users/create') ?>
<div>
<?= form_label('Email') ?>
<?= form_input('email', set_value('email')) ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email')]) ?>
<?= form_error('email', '<div><span>', '</span></div>') ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Doctrine/Common/EditView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div>
<?= form_label('Email') ?>
<?= form_input('email', set_value('email', $item->get_email())) ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email', $item->get_email())]) ?>
<?= form_error('email', '<div><span>', '</span></div>') ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Doctrine/Styled/CreateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?= form_open('users/create') ?>
<div class="mb-3">
<?= form_label('Email', '', ['class' => 'form-label mb-0']) ?>
<?= form_input('email', set_value('email'), 'class="form-control"') ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email'), 'class' => 'form-control']) ?>
<?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Doctrine/Styled/EditView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div class="mb-3">
<?= form_label('Email', '', ['class' => 'form-label mb-0']) ?>
<?= form_input('email', set_value('email', $item->get_email()), 'class="form-control"') ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email', $item->get_email()), 'class' => 'form-control']) ?>
<?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Wildfire/Common/CreateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?= form_open('users/create') ?>
<div>
<?= form_label('Email') ?>
<?= form_input('email', set_value('email')) ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email')]) ?>
<?= form_error('email', '<div><span>', '</span></div>') ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Wildfire/Common/EditView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div>
<?= form_label('Email') ?>
<?= form_input('email', set_value('email', $item->email)) ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email', $item->email)]) ?>
<?= form_error('email', '<div><span>', '</span></div>') ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Wildfire/Styled/CreateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?= form_open('users/create') ?>
<div class="mb-3">
<?= form_label('Email', '', ['class' => 'form-label mb-0']) ?>
<?= form_input('email', set_value('email'), 'class="form-control"') ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email'), 'class' => 'form-control']) ?>
<?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?>
</div>

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Plates/Wildfire/Styled/EditView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div class="mb-3">
<?= form_label('Email', '', ['class' => 'form-label mb-0']) ?>
<?= form_input('email', set_value('email', $item->email), 'class="form-control"') ?>
<?= form_input(['type' => 'email', 'name' => 'email', 'value' => set_value('email', $item->email), 'class' => 'form-control']) ?>
<?= form_error('email', '<div><span class="text-danger small">', '</span></div>') ?>
</div>

Expand Down

0 comments on commit 018e1e4

Please sign in to comment.