From 28d58569089fc4f91950df31151e85e3e3350187 Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Sat, 29 Mar 2025 01:41:05 -0700 Subject: [PATCH] override table trait for other cake plugins controllers --- src/Controller/Traits/OverrideTableTrait.php | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/Controller/Traits/OverrideTableTrait.php diff --git a/src/Controller/Traits/OverrideTableTrait.php b/src/Controller/Traits/OverrideTableTrait.php new file mode 100644 index 0000000..a2b17b7 --- /dev/null +++ b/src/Controller/Traits/OverrideTableTrait.php @@ -0,0 +1,70 @@ +_table instanceof Table) { + return $this->_table; + } + $this->getTableConfigKey(); + $table = $tableName; + if (!isset($table)) { + $table = $this->defaultTable; + if (Configure::read($this->_tableConfigKey)) { + $table = Configure::read($this->_tableConfigKey); + } + } + $this->_table = TableRegistry::getTableLocator()->get($table); + + return $this->_table; + } + + protected function getTableConfigKey() + { + if (!$this->_tableConfigKey) { + $this->_tableConfigKey = $this->getPlugin() . '.' . $this->defaultTable . '.table'; + } + + return $this->_tableConfigKey; + } + + /** + * Set the users table + * + * @param Table $table table + * @return void + */ + public function setTable(Table $table) + { + $this->_table = $table; + } +} \ No newline at end of file