From 2278185f15c7903b3b223ff4d07fe7da5c393525 Mon Sep 17 00:00:00 2001 From: Tortue Torche Date: Tue, 21 Jan 2014 17:22:55 +0100 Subject: [PATCH] Tidying up pull request. Many thanks to Anahkiasen :) --- src/Former/Framework/TwitterBootstrap3.php | 21 ++++++++++++++++++++- src/Former/Traits/Checkable.php | 13 +------------ src/Former/Traits/Framework.php | 13 +++++++++++++ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/Former/Framework/TwitterBootstrap3.php b/src/Former/Framework/TwitterBootstrap3.php index 99530ab7..74146d0c 100644 --- a/src/Former/Framework/TwitterBootstrap3.php +++ b/src/Former/Framework/TwitterBootstrap3.php @@ -147,6 +147,25 @@ public function errorState() return 'has-error'; } + /** + * Returns corresponding inline class of a field + * + * @param Field $field + * + * @return string + */ + public function getInlineLabelClass($field) + { + $inlineClass = 'inline'; + if ($field->isOfType('checkbox', 'checkboxes')) { + $inlineClass = 'checkbox-'.$inlineClass; + } elseif ($field->isOfType('radio', 'radios')) { + $inlineClass = 'radio-'.$inlineClass; + } + + return $inlineClass; + } + /** * Set the fields width from a label width * @@ -185,7 +204,7 @@ protected function setFieldWidths($labelWidths) public function getFieldClasses(Field $field, $classes) { // Add inline class for checkables - if ($field->isCheckable() and count(array_intersect(array('inline', 'checkbox-inline', 'radio-inline'), $classes)) > 0) { + if ($field->isCheckable() and in_array('inline', $classes)) { $field->inline(); } diff --git a/src/Former/Traits/Checkable.php b/src/Former/Traits/Checkable.php index 96096327..fef83d96 100644 --- a/src/Former/Traits/Checkable.php +++ b/src/Former/Traits/Checkable.php @@ -309,18 +309,7 @@ protected function createCheckable($item, $fallbackValue = 1) } // If inline items, add class - $isInline = null; - if ($this->inline) { - $inlineClass = 'inline'; - if ($this->app['former.framework']->current() === 'TwitterBootstrap3') { - if ($this->isOfType('checkbox', 'checkboxes')) { - $inlineClass = 'checkbox-'.$inlineClass; - } elseif ($this->isOfType('radio', 'radios')) { - $inlineClass = 'radio-'.$inlineClass; - } - } - $isInline = ' '.$inlineClass; - } + $isInline = $this->inline ? ' '.$this->app['former.framework']->getInlineLabelClass($this) : null; // Merge custom attributes with global attributes $attributes = array_merge($this->attributes, $attributes); diff --git a/src/Former/Traits/Framework.php b/src/Former/Traits/Framework.php index 130c054e..392d8c3f 100644 --- a/src/Former/Traits/Framework.php +++ b/src/Former/Traits/Framework.php @@ -147,6 +147,19 @@ public function errorState() return 'error'; } + + /** + * Returns corresponding inline class of a field + * + * @param Field $field + * + * @return string + */ + public function getInlineLabelClass($field) + { + return 'inline'; + } + /** * Set framework defaults from its config file */