Documentation

Create the new table into the extension

Or copy link

Create the new table into the extension

Estimated reading: minutes 5 views

5 views
Min read

Here we are going to provide a front-end form to apply for the job, and before that, we will add one more table for the “job” into the back-end module of the extension we have created above, and perform the CRUD operation for the job.

To add the Job in the existing extension add relevant code into the ext_tables.sql file, create its TCA file, create a model file & other pieces of stuff as per requirement. Let’s start to create the custom form in the front-end.

Create a new table for the job

Create a table for the “Job” in the ext_tables.sql file, add the code below to create the table for the job.

CREATE TABLE tx_employee_domain_model_job ( 
	job_title varchar(255) DEFAULT '' NOT NULL,
	vacancy  varchar(255) DEFAULT '' NOT NULL,
	slug  varchar(255) DEFAULT '' NOT NULL,
	banner_image  int(11) unsigned DEFAULT '0',
	job_description text,
	job_location  varchar(255) DEFAULT '' NOT NULL,
	publish_date int(11) DEFAULT '0' NOT NULL,
	job_type varchar(255) DEFAULT '' NOT NULL,
	years_of_experience varchar(255) DEFAULT '' NOT NULL,
	working_hrs varchar(255) DEFAULT '' NOT NULL,
	working_days varchar(255) DEFAULT '' NOT NULL,
	salary varchar(255) DEFAULT '' NOT NULL,
	job_requirements text,
	education_qualification text,
	perks_benefits text, 
);

Create a TCA file for the job table

1. Create a TCA file for the Job table, and the name of the TCA file should be in this format tx_extensionkey_domain_model_tablename, and here it will be tx_employee_domain_model_job.php.

2. The path for the TCA file is employeeConfigurationTCAtx_employee_domain_model_job.php

3. Add the code below to the TCA file tx_employee_domain_model_job.php

<?php
return [
'ctrl' => [
'title' => 'Job',
'label' => 'job_title',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'versioningWS' => true,
'label_alt_force' => true,
'origUid' => 't3_origuid',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => [
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
],
'searchFields' => 'job_title',
'vacancy',
'slug',
'banner_image',
'job_description',
'job_location',
'publish_date',
'years_of_experience',
'working_hrs',
'working_days',
'salary',
'job_requirements',
'education_qualification',
'perks_benefits',
'iconfile' => 'EXT:employee/Resources/Public/Icons/Extension.png',
'security' => [
'ignorePageTypeRestriction' => true,
],
],
'types' => [
'1' => [
'showitem' => 'job_title,vacancy,slug,job_type,banner_image,job_description,job_location,publish_date,years_of_experience,working_hrs,working_days,salary,job_requirements,education_qualification,perks_benefits, --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language, sys_language_uid, l10n_parent, l10n_diffsource, --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, hidden, starttime, endtime'
],
],
'columns' => [
'sys_language_uid' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'language',
],
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'default' => 0,
'items' => [
['label' => '', 'value' => 0]
],
'foreign_table' => 'tx_employee_domain_model_job',
'foreign_table_where' => 'AND {#tx_employee_domain_model_job}.{#pid}=###CURRENT_PID### AND {#tx_employee_domain_model_job}.{#sys_language_uid} IN (-1,0)',
],
],
'l10n_diffsource' => [
'config' => [
'type' => 'passthrough',
],
],
'hidden' => [
'config' => [
'type' => 'check',
'items' => [
['label' => 'Disable'],
],
]
],
'starttime' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.starttime',
'config' => [
'type' => 'input',
'renderType' => 'datetime',
'eval' => 'datetime,int',
'default' => 0,
'behaviour' => [
'allowLanguageSynchronization' => true
]
],
],
'endtime' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.endtime',
'config' => [
'type' => 'input',
'renderType' => 'datetime',
'eval' => 'datetime,int',
'default' => 0,
'range' => [
'upper' => mktime(0, 0, 0, 1, 1, 2038)
],
'behaviour' => [
'allowLanguageSynchronization' => true
]
],
],

'job_title' => [
'l10n_mode' => 'prefixLangTitle',
'label' => 'Job Title',
'description' => 'Enter Job Title',
'config' => [
'type' => 'input',
'behaviour' => [
'allowLanguageSynchronization' => true,
],
]

],
'vacancy' => [
'l10n_mode' => 'prefixLangTitle',
'label' => 'Job Vacancy',
'description' => 'Enter Job Vacancy',
'config' => [
'type' => 'input',
'behaviour' => [
'allowLanguageSynchronization' => true,
],
]
],
'slug' => [
'label' => 'Slug',
'config' => [
'type' => 'slug',
'generatorOptions' => [
'fields' => ['job_title'],
'replacements' => [
'/' => '-',
],
],
'fallbackCharacter' => '-',
'eval' => 'uniqueInSite',
'uniqueInPid',
'default' => '',
'appearance' => [
'prefix' => CompanyEmployeeUserFunctionsFormEngineSlugPrefix::class . '->getPrefix'
],

],
],

'banner_image' => [
'label' => 'Banner',
'config' => [
'type' => 'file',
'maxitems' => 1,
'allowed' => 'common-image-types'
],
],
'job_description' => [
'label' => 'Description',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
'job_location' => [
'label' => 'Location',
'config' => [
'type' => 'input',
]
],
'publish_date' => [
'label' => 'Publish Date',
'config' => [
'type' => 'datetime',
'format' => 'date',
'eval' => 'int',
'default' => 0,
]
],
"job_type" => [
'label' => 'Job Type',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'label' => 'Full Time',
'value' => 'full-time',
],
[
'label' => 'Part Time',
'value' => 'part-time',
],
[
'label' => 'Work From Home',
'value' => 'wfh',
],
],
],
],
'years_of_experience' => [
'label' => 'Experience Year',
'config' => [
'type' => 'number',
'format' => 'decimal'
]
],
'working_hrs' => [
'label' => 'Working hour',
'config' => [
'type' => 'input',
]
],
'working_days' => [
'label' => 'Working Days',
'config' => [
'type' => 'number',
'format' => 'decimal'
]
],
'salary' => [
'label' => 'Salary',
'config' => [
'type' => 'number',
'format' => 'decimal'
]
],
'job_requirements' => [
'label' => 'Requirements',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
'education_qualification' => [
'label' => 'Qualification',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
'perks_benefits' => [
'label' => 'Benefits',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
],
];

4. Here we need to use the custom function to add the prefix URL for the slug field, to create that custom function create the file SlugPrefix.php, the path of the file is employeeClassesUserFunctionsFormEngineSlugPrefix.php.

  1. Add the code below in the file SlugPrefix.php
<?php
declare(strict_types = 1);

namespace CompanyEmployeeUserFunctionsFormEngine;

use TYPO3CMSBackendFormFormDataProviderTcaSlug;

class SlugPrefix
{
public function getPrefix(array $parameters, TcaSlug $reference): string
{
return '/job';
}
}

Create the model for the job table

1. Create the model file Job.php for the job table and the file path for the job model is employeeClassesDomainModelJob.php

2. Add the code below to the Job.php file

<?php

declare(strict_types=1);

namespace CompanyEmployeeDomainModel;

use DateTime;
use TYPO3CMSExtbaseDomainObjectAbstractEntity;
use TYPO3CMSExtbaseAnnotationORMLazy;
use TYPO3CMSExtbaseDomainModelFileReference;
use TYPO3CMSExtbasePersistenceGenericLazyLoadingProxy;
use TYPO3CMSExtbasePersistenceObjectStorage;

/**
* Job Model
*/
class Job extends AbstractEntity
{
/**
* jobTitle
*
* @var string
*/
protected $jobTitle = '';

/**
* vacancy
*
* @var string
*/
protected $vacancy = '';

/**
* slug
*
* @var string
*/
protected $slug = '';


/**
* @Lazy
* @var TYPO3CMSExtbasePersistenceObjectStorage<TYPO3CMSExtbaseDomainModelFileReference>
*/
protected ObjectStorage $bannerImage;


/**
* jobDescription
*
* @var string
*/
protected $jobDescription = '';

/**
* jobLocation
*
* @var string
*/
protected $jobLocation = '';

/**
* publishDate
*
* @var DateTime
*/
protected $publishDate;

/**
* jobType
*
* @var string
*/
protected $jobType = '';

/**
* yearsOfExperience
*
* @var string
*/
protected $yearsOfExperience = '';

/**
* workingHrs
*
* @var string
*/
protected $workingHrs = '';

/**
* workingDays
*
* @var string
*/
protected $workingDays = '';

/**
* salary
*
* @var string
*/
protected $salary = '';

/**
* jobRequirements
*
* @var string
*/
protected $jobRequirements = '';

/**
* educationQualification
*
* @var string
*/
protected $educationQualification = '';

/**
* perksBenefits
*
* @var string
*/
protected $perksBenefits = '';


public function __construct()
{
$this->initializeObject();

}

public function initializeObject(): void
{
$this->bannerImage = $this->bannerImage ?? new ObjectStorage();
}

/**
* Returns the jobTitle
*
* @return string
*/
public function getJobTitle(): string
{
return $this->jobTitle;
}

/**
* Sets the jobTitle
*
* @param string $jobTitle
* @return void
*/
public function setJobTitle(string $jobTitle): void
{
$this->jobTitle = $jobTitle;
}


/**
* Returns the vacancy
*
* @return string
*/
public function getVacancy(): string
{
return $this->vacancy;
}

/**
* Sets the vacancy
*
* @param string $vacancy
* @return void
*/
public function setVacancy(string $vacancy): void
{
$this->vacancy = $vacancy;
}

/**
* Returns the slug
*
* @return string
*/
public function getSlug(): string
{
return $this->slug;
}
/**
* Sets the slug
*
* @param string $slug
* @return void
*/
public function setSlug(string $slug): void
{
$this->slug = $slug;
}

/**
* @return TYPO3CMSExtbasePersistenceObjectStorage<TYPO3CMSExtbaseDomainModelFileReference>
*/
public function getBannerImage(): ObjectStorage
{
return $this->bannerImage;
}

/**
* @param TYPO3CMSExtbasePersistenceObjectStorage<TYPO3CMSExtbaseDomainModelFileReference> $bannerImage
*/
public function setBannerImage(ObjectStorage $bannerImage): self
{
$this->bannerImage = $bannerImage;
return $this;
}




/**
* Returns the jobDescription
*
* @return string
*/
public function getJobDescription(): string
{
return $this->jobDescription;
}
/**
* Sets the jobDescription
*
* @param string $jobDescription
* @return void
*/
public function setJobDescription(string $jobDescription): void
{
$this->jobDescription = $jobDescription;
}

/**
* Returns the jobLocation
*
* @return string
*/
public function getJobLocation(): string
{
return $this->jobLocation;
}
/**
* Sets the jobLocation
*
* @param string $jobLocation
* @return void
*/
public function setJobLocation(string $jobLocation): void
{
$this->jobLocation = $jobLocation;
}


/**
* Get publishDate
*
* @return DateTime|null
*/
public function getPublishDate(): ?DateTime
{
return $this->publishDate;
}

/**
* Set publishDate
*
* @param DateTime $publishDate
*/
public function setPublishDate(DateTime $publishDate): void
{
$this->publishDate = $publishDate;
}

/**
* Get year of publishDate
*
* @return int
*/
public function getYearOfPublishDate(): int
{
if ($this->getPublishDate()) {
return (int) $this->getPublishDate()->format('Y');
}
return 0;
}

/**
* Get month of publishDate
*
* @return int
*/
public function getMonthOfPublishDate(): int
{
if ($this->getPublishDate()) {
return (int) $this->getPublishDate()->format('m');
}
return 0;
}

/**
* Get day of publishDate
*
* @return int
*/
public function getDayOfPublishDate(): int
{
if ($this->publishDate) {
return (int) $this->publishDate->format('d');
}
return 0;
}


/**
* Returns the jobType
*
* @return string
*/
public function getJobType(): string
{
return $this->jobType;
}
/**
* Sets the jobType
*
* @param string $jobType
* @return void
*/
public function setJobType(string $jobType): void
{
$this->jobType = $jobType;
}


/**
* Returns the yearsOfExperience
*
* @return string
*/
public function getYearsOfExperience(): string
{
return $this->yearsOfExperience;
}
/**
* Sets the yearsOfExperience
*
* @param string $yearsOfExperience
* @return void
*/
public function setYearsOfExperience(string $yearsOfExperience): void
{
$this->yearsOfExperience = $yearsOfExperience;
}

/**
* Returns the workingHrs
*
* @return string
*/
public function getWorkingHrs(): string
{
return $this->workingHrs;
}
/**
* Sets the workingHrs
*
* @param string $workingHrs
* @return void
*/
public function setWorkingHrs(string $workingHrs): void
{
$this->workingHrs = $workingHrs;
}

/**
* Returns the workingDays
*
* @return string
*/
public function getWorkingDays(): string
{
return $this->workingDays;
}
/**
* Sets the workingDays
*
* @param string $workingDays
* @return void
*/
public function setWorkingDays(string $workingDays): void
{
$this->workingDays = $workingDays;
}
/**
* Returns the salary
*
* @return string
*/
public function getSalary(): string
{
return $this->salary;
}
/**
* Sets the salary
*
* @param string $salary
* @return void
*/
public function setSalary(string $salary): void
{
$this->salary = $salary;
}

/**
* Returns the jobRequirements
*
* @return string
*/
public function getJobRequirements(): string
{
return $this->jobRequirements;
}
/**
* Sets the jobRequirements
*
* @param string $jobRequirements
* @return void
*/
public function setJobRequirements(string $jobRequirements): void{
$this->jobRequirements = $jobRequirements;
}

/**
* Returns the educationQualification
*
* @return string
*/
public function getEducationQualification(): string
{
return $this->educationQualification;
}
/**
* Sets the educationQualification
*
* @param string $educationQualification
* @return void
*/
public function setEducationQualification(string $educationQualification): void{
$this->educationQualification = $educationQualification;
}
/**
* Returns the perksBenefits
*
* @return string
*/
public function getPerksBenefits(): string
{
return $this->perksBenefits;
}
/**
* Sets the perksBenefits
*
* @param string $perksBenefits
* @return void
*/
public function setPerksBenefits(string $perksBenefits): void{
$this->perksBenefits = $perksBenefits;
}

}

Create a repository for the job model

  1. Let’s create a repository JobRepository.php that can be use to perform any operation on Job from the back-end module or from the front-end plugin.
  2. The file path for the repository is employeeClassesDomainRepositoryJobRepository.php
  3. Add the code below to the JobRepository.php file
<?php

declare(strict_types=1);

namespace CompanyEmployeeDomainRepository;

use TYPO3CMSExtbasePersistenceRepository;
use TYPO3CMSExtbasePersistenceGenericTypo3QuerySettings;
use TYPO3CMSCoreUtilityGeneralUtility;
use TYPO3CMSExtbasePersistenceGenericQuerySettingsInterface;

/**
* The repository for Job
*/
class JobRepository extends Repository
{
public function initializeObject()
{
/** @var QuerySettingsInterface $querySettings */
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($querySettings);
}
}
Share

Leave a Comment